OpenSearch/distribution/build.gradle

199 lines
7.7 KiB
Groovy

/*
* Licensed to Elasticsearch under one or more contributor
* license agreements. See the NOTICE file distributed with
* this work for additional information regarding copyright
* ownership. Elasticsearch licenses this file to you under
* the Apache License, Version 2.0 (the "License"); you may
* not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing,
* software distributed under the License is distributed on an
* "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
* KIND, either express or implied. See the License for the
* specific language governing permissions and limitations
* under the License.
*/
import org.apache.tools.ant.filters.FixCrLfFilter
import org.elasticsearch.gradle.precommit.DependencyLicensesTask
import org.elasticsearch.gradle.MavenFilteringHack
// for deb/rpm
buildscript {
repositories {
maven {
url "https://plugins.gradle.org/m2/"
}
}
dependencies {
classpath 'com.netflix.nebula:gradle-ospackage-plugin:3.1.0'
}
}
allprojects {
project.ext {
// this is common configuration for distributions, but we also add it here for the license check to use
dependencyFiles = project("${projectsPrefix}:core").configurations.runtime.copyRecursive().exclude(module: 'slf4j-api')
}
}
subprojects {
/*****************************************************************************
* Rest test config *
*****************************************************************************/
apply plugin: 'elasticsearch.rest-test'
integTest {
includePackaged true
}
/*****************************************************************************
* Maven config *
*****************************************************************************/
// note: the group must be correct before applying the nexus plugin, or it will capture the wrong value...
project.group = "org.elasticsearch.distribution.${project.name}"
apply plugin: 'com.bmuschko.nexus'
// we must create our own install task, because it is only added when the java plugin is added
task install(type: Upload, description: "Installs the 'archives' artifacts into the local Maven repository.", group: 'Upload') {
configuration = configurations.archives
MavenRepositoryHandlerConvention repositoriesHandler = (MavenRepositoryHandlerConvention)getRepositories().getConvention().getPlugin(MavenRepositoryHandlerConvention)
repositoriesHandler.mavenInstaller()
}
// TODO: the map needs to be an input of the tasks, so that when it changes, the task will re-run...
/*****************************************************************************
* Properties to expand when copying packaging files *
*****************************************************************************/
project.ext {
expansions = [
'project.version': version,
'project.parent.artifactId': 'distributions',
// Default values for min/max heap memory allocated to elasticsearch java process
'packaging.elasticsearch.heap.min': '256m',
'packaging.elasticsearch.heap.max': '1g',
'project.build.finalName': "elasticsearch-${version}",
// Default configuration directory and file to use in bin/plugin script
'packaging.plugin.default.config.dir': '$ES_HOME/config',
'packaging.plugin.default.config.file': '$ES_HOME/config/elasticsearch.yml',
'packaging.env.file': '',
// TODO: do we really need this marker? the tgz and zip are exactly the same,
// we should not need to specify twice just to change this
'packaging.type': 'tar.gz',
]
/*****************************************************************************
* Common files in all distributions *
*****************************************************************************/
libFiles = copySpec {
into 'lib'
from project("${projectsPrefix}:core").jar
from dependencyFiles
}
configFiles = copySpec {
from '../src/main/resources/config'
}
commonFiles = copySpec {
// everything except windows files, and config is separate
from '../src/main/resources'
exclude 'bin/*.bat'
exclude 'bin/*.exe'
exclude 'config/**'
filesMatching('bin/*') { it.setMode(0755) }
}
}
}
/*****************************************************************************
* Zip and tgz configuration *
*****************************************************************************/
configure(subprojects.findAll { it.name == 'zip' || it.name == 'tar' }) {
project.ext.archivesFiles = copySpec {
into("elasticsearch-${version}") {
with libFiles
into('config') {
with configFiles
}
with copySpec {
with commonFiles
from('../src/main/resources') {
include 'bin/*.bat'
filter(FixCrLfFilter, eol: FixCrLfFilter.CrLf.newInstance('crlf'))
}
MavenFilteringHack.filter(it, expansions)
}
from('../src/main/resources') {
include 'bin/*.exe'
}
}
}
}
/*****************************************************************************
* Deb and rpm configuration *
*****************************************************************************/
// ospackage supports adding empty dirs with directory() to rpm, but not deb...yet
// https://github.com/nebula-plugins/gradle-ospackage-plugin/issues/115
// however, even adding just for rpm doesn't seem to work...
// gradle may also get native support https://issues.gradle.org/browse/GRADLE-1671
// in the meantime, we hack this by copying an empty dir
// TODO: HACK DOES NOT WORK
/*ext.emptyDir = new File(project.buildDir, 'empty')
Closure emptyDirSpec() {
return {
from emptyDir
addParentDirs false
createDirectoryEntry true
}
}
task createEmptyDir << {
emptyDir.mkdirs()
}
buildRpm.dependsOn createEmptyDir
buildDeb.dependsOn createEmptyDir
*/
/*****************************************************************************
* Deb and rpm configuration *
*****************************************************************************/
configure(subprojects.findAll { it.name == 'deb' || it.name == 'rpm' }) {
apply plugin: 'nebula.ospackage-base'
ospackage {
packageName = 'elasticsearch'
// TODO: '-' is an illegal character in rpm version...redline croaks
version = '3.0.0'
into '/usr/share/elasticsearch'
user 'root'
permissionGroup 'root'
with libFiles
with copySpec {
with commonFiles
// TODO: omit LICENSE.txt file on deb??
}
into('/etc/elasticsearch') {
with configFiles
//into('scripts', emptyDirSpec())
createDirectoryEntry = true
includeEmptyDirs = true
}
directory('/etc/elasticsearch/scripts')
}
// TODO: re-enable tests when we have real rpm and deb distros!
integTest.enabled = false
}
// TODO: dependency checks should really be when building the jar itself, which would remove the need
// for this hackery and instead we can do this inside the BuildPlugin
task check(group: 'Verification', description: 'Runs all checks.') {} // dummy task!
DependencyLicensesTask.configure(project) {
dependsOn = [dependencyFiles]
dependencies = dependencyFiles
mapping from: /lucene-.*/, to: 'lucene'
mapping from: /jackson-.*/, to: 'jackson'
}
task run(type:org.elasticsearch.gradle.test.RunTask){}