OpenSearch/build.gradle

258 lines
8.5 KiB
Groovy

description = 'Builds the Machine Learning Java classes and UI'
import org.gradle.internal.os.OperatingSystem
import org.gradle.plugins.ide.eclipse.model.SourceFolder
import org.elasticsearch.gradle.precommit.LicenseHeadersTask
import org.elasticsearch.gradle.VersionProperties
import org.elastic.gradle.UploadS3Task
String envMlAwsAccessKey = System.env.PRELERT_AWS_ACCESS_KEY_ID
if (envMlAwsAccessKey != null) {
project.ext.mlAwsAccessKey = envMlAwsAccessKey
} else if (project.hasProperty("PRELERT_AWS_ACCESS_KEY_ID")) {
project.ext.mlAwsAccessKey = PRELERT_AWS_ACCESS_KEY_ID
}
String envMlAwsSecretKey = System.env.PRELERT_AWS_SECRET_ACCESS_KEY
if (envMlAwsSecretKey != null) {
project.ext.mlAwsSecretKey = envMlAwsSecretKey
} else if (project.hasProperty("PRELERT_AWS_SECRET_ACCESS_KEY")) {
project.ext.mlAwsSecretKey = PRELERT_AWS_SECRET_ACCESS_KEY
}
String envCppLocalDists = System.env.CPP_LOCAL_DISTS
if (envCppLocalDists != null) {
project.ext.cppLocalDists = envCppLocalDists
} else if (project.hasProperty("CPP_LOCAL_DISTS")) {
project.ext.cppLocalDists = CPP_LOCAL_DISTS
} else {
project.ext.cppLocalDists = ''
}
project.ext.isWindows = OperatingSystem.current().isWindows()
project.ext.isLinux = OperatingSystem.current().isLinux()
project.ext.isMacOsX = OperatingSystem.current().isMacOsX()
String uploadEnabledStr = properties.get('upload', 'false')
if (['true', 'false'].contains(uploadEnabledStr) == false) {
throw new GradleException("upload must be true or false, got ${uploadEnabledStr}")
}
project.ext.uploadEnabled = uploadEnabledStr == 'true'
allprojects {
group = 'org.elasticsearch.ml'
version = VersionProperties.elasticsearch
}
String packArtifactName = 'ml'
configurations.all {
// check for updates every build
resolutionStrategy.cacheChangingModulesFor 0, 'seconds'
}
buildscript {
repositories {
if (System.getProperty("repos.mavenlocal") != null) {
// with -Drepos.mavenlocal=true we can force checking the local .m2 repo which is useful for building against
// elasticsearch snapshots
mavenLocal()
}
mavenCentral()
maven {
name 'sonatype-snapshots'
url "https://oss.sonatype.org/content/repositories/snapshots/"
}
jcenter()
}
dependencies {
classpath group: 'org.elasticsearch.gradle', name: 'build-tools', version: "${elasticsearchVersion}", changing: true
}
}
subprojects {
// we must not publish to sonatype until we have set up x-plugins to only publish the parts we want to publish!
project.afterEvaluate {
if (project.plugins.hasPlugin('com.bmuschko.nexus') && project.nexus.repositoryUrl.startsWith('file://') == false) {
uploadArchives.enabled = false
}
}
}
task bundlePack(type: Zip) {
onlyIf { project('kibana').bundlePlugin.enabled }
dependsOn 'elasticsearch:bundlePlugin'
dependsOn 'kibana:bundlePlugin'
from { zipTree(project('elasticsearch').bundlePlugin.outputs.files.singleFile) }
from { zipTree(project('kibana').bundlePlugin.outputs.files.singleFile) }
destinationDir file('build/distributions')
baseName = packArtifactName
version = project.version
}
task assemble(dependsOn: bundlePack) {
group = 'Build'
description = 'Assembles the outputs of this project.'
}
task test(dependsOn: [':elasticsearch:test', ':kibana:test']) {
group = 'Build'
description = 'Assembles and tests this project.'
}
task build(dependsOn: [assemble, test]) {
group = 'Build'
description = 'Assembles and tests this project.'
}
task clean(type: Delete) {
group = 'Build'
description = 'Deletes the build directory'
delete 'build'
}
task uploadPackToS3(type: UploadS3Task, dependsOn: build) {
enabled project.uploadEnabled
description = 'upload pack zip to S3 Bucket'
bucket 'prelert-artifacts'
upload bundlePack.outputs.files.singleFile, "maven/${project.group}/${packArtifactName}/${project.version}/${bundlePack.outputs.files.singleFile.name}"
}
task deploy(dependsOn: uploadPackToS3) {
}
subprojects {
apply plugin: 'eclipse'
apply plugin: 'idea'
buildscript {
repositories {
if (System.getProperty("repos.mavenlocal") != null) {
// with -Drepos.mavenlocal=true we can force checking the local .m2 repo which is useful for building against
// elasticsearch snapshots
mavenLocal()
}
mavenCentral()
maven {
name 'sonatype-snapshots'
url "https://oss.sonatype.org/content/repositories/snapshots/"
}
jcenter()
}
}
repositories {
if (System.getProperty("repos.mavenlocal") != null) {
// with -Drepos.mavenlocal=true we can force checking the local .m2 repo which is useful for building against
// elasticsearch snapshots
mavenLocal()
}
mavenCentral()
maven {
name 'sonatype-snapshots'
url "https://oss.sonatype.org/content/repositories/snapshots/"
}
jcenter()
}
tasks.withType(LicenseHeadersTask.class) {
approvedLicenses = ['Elasticsearch Confidential']
additionalLicense 'ESCON', 'Elasticsearch Confidential', 'ELASTICSEARCH CONFIDENTIAL'
}
}
allprojects {
// injecting groovy property variables into all projects
project.ext {
// for ide hacks...
isEclipse = System.getProperty("eclipse.launcher") != null || gradle.startParameter.taskNames.contains('eclipse') || gradle.startParameter.taskNames.contains('cleanEclipse')
isIdea = System.getProperty("idea.active") != null || gradle.startParameter.taskNames.contains('idea') || gradle.startParameter.taskNames.contains('cleanIdea')
}
}
allprojects {
apply plugin: 'idea'
if (isIdea) {
project.buildDir = file('build-idea')
}
idea {
module {
inheritOutputDirs = false
outputDir = file('build-idea/classes/main')
testOutputDir = file('build-idea/classes/test')
// also ignore other possible build dirs
excludeDirs += file('build')
excludeDirs += file('build-eclipse')
iml {
// fix so that Gradle idea plugin properly generates support for resource folders
// see also https://issues.gradle.org/browse/GRADLE-2975
withXml {
it.asNode().component.content.sourceFolder.findAll { it.@url == 'file://$MODULE_DIR$/src/main/resources' }.each {
it.attributes().remove('isTestSource')
it.attributes().put('type', 'java-resource')
}
it.asNode().component.content.sourceFolder.findAll { it.@url == 'file://$MODULE_DIR$/src/test/resources' }.each {
it.attributes().remove('isTestSource')
it.attributes().put('type', 'java-test-resource')
}
}
}
}
}
}
// Make sure gradle idea was run before running anything in intellij (including import).
File ideaMarker = new File(projectDir, '.local-idea-is-configured')
tasks.idea.doLast {
ideaMarker.setText('', 'UTF-8')
}
if (System.getProperty('idea.active') != null && ideaMarker.exists() == false) {
throw new GradleException('You must run gradle idea from the root of elasticsearch before importing into IntelliJ')
}
// eclipse configuration
allprojects {
apply plugin: 'eclipse'
// Name all the non-root projects after their path so that paths get grouped together when imported into eclipse.
if (path != ':') {
eclipse.project.name = path
if (isWindows) {
eclipse.project.name = eclipse.project.name.replace(':', '_')
}
}
plugins.withType(JavaBasePlugin) {
File eclipseBuild = project.file('build-eclipse')
eclipse.classpath.defaultOutputDir = eclipseBuild
if (isEclipse) {
// set this so generated dirs will be relative to eclipse build
project.buildDir = eclipseBuild
}
eclipse.classpath.file.whenMerged { classpath ->
// give each source folder a unique corresponding output folder
int i = 0;
classpath.entries.findAll { it instanceof SourceFolder }.each { folder ->
i++;
// this is *NOT* a path or a file.
folder.output = "build-eclipse/" + i
}
}
}
task copyEclipseSettings(type: Copy) {
// TODO: "package this up" for external builds
from new File(project.rootDir, 'buildSrc/src/main/resources/eclipse.settings')
into '.settings'
}
// otherwise .settings is not nuked entirely
task wipeEclipseSettings(type: Delete) {
delete '.settings'
}
tasks.cleanEclipse.dependsOn(wipeEclipseSettings)
// otherwise the eclipse merging is *super confusing*
tasks.eclipse.dependsOn(cleanEclipse, copyEclipseSettings)
}