123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294 |
- /*
- * Copyright Elasticsearch B.V. and/or licensed to Elasticsearch B.V. under one
- * or more contributor license agreements. Licensed under the Elastic License
- * 2.0 and the Server Side Public License, v 1; you may not use this file except
- * in compliance with, at your election, the Elastic License 2.0 or the Server
- * Side Public License, v 1.
- */
- import org.gradle.internal.jvm.Jvm
- plugins {
- id 'java-gradle-plugin'
- id 'groovy'
- id 'java-test-fixtures'
- }
- group = 'org.elasticsearch.gradle'
- if (project == rootProject) {
- // change the build dir used during build init, so that doing a clean
- // won't wipe out the buildscript jar
- buildDir = 'build-bootstrap'
- }
- /*****************************************************************************
- * Propagating version.properties to the rest of the build *
- *****************************************************************************/
- // we update the version property to reflect if we are building a snapshot or a release build
- // we write this back out below to load it in the Build.java which will be shown in rest main action
- // to indicate this being a snapshot build or a release build.
- Properties props = VersionPropertiesLoader.loadBuildSrcVersion(project.file('version.properties'))
- version = props.getProperty("elasticsearch")
- gradlePlugin {
- // We already configure publication and we don't need or want the one that comes
- // with the java-gradle-plugin
- automatedPublishing = false
- }
- def generateVersionProperties = tasks.register("generateVersionProperties", WriteProperties) {
- outputFile = "${buildDir}/version.properties"
- comment = 'Generated version properties'
- properties(props)
- }
- tasks.named("processResources").configure {
- from(generateVersionProperties)
- }
- /*****************************************************************************
- * Java version *
- *****************************************************************************/
- if (JavaVersion.current() < JavaVersion.VERSION_11) {
- throw new GradleException('At least Java 11 is required to build elasticsearch gradle tools')
- }
- allprojects {
- apply plugin: 'java'
- targetCompatibility = '11'
- sourceCompatibility = '11'
- }
- sourceSets {
- integTest {
- compileClasspath += sourceSets["main"].output + configurations["testRuntimeClasspath"]
- runtimeClasspath += output + compileClasspath
- }
- }
- tasks.withType(JavaCompile).configureEach {
- options.encoding = 'UTF-8'
- }
- /*****************************************************************************
- * Dependencies used by the entire build *
- *****************************************************************************/
- repositories {
- mavenCentral()
- gradlePluginPortal()
- }
- dependencies {
- api localGroovy()
- api gradleApi()
- api 'commons-codec:commons-codec:1.12'
- api 'org.apache.commons:commons-compress:1.19'
- api 'org.apache.ant:ant:1.10.8'
- api 'com.netflix.nebula:gradle-extra-configurations-plugin:5.0.1'
- api 'com.netflix.nebula:gradle-info-plugin:9.2.0'
- api 'org.apache.rat:apache-rat:0.11'
- api "org.elasticsearch:jna:5.7.0-1"
- api 'com.github.jengelman.gradle.plugins:shadow:6.1.0'
- // When upgrading forbidden apis, ensure dependency version is bumped in ThirdPartyPrecommitPlugin as well
- api 'de.thetaphi:forbiddenapis:3.1'
- api 'com.avast.gradle:gradle-docker-compose-plugin:0.14.0'
- api 'org.apache.maven:maven-model:3.6.2'
- api 'com.networknt:json-schema-validator:1.0.36'
- api "com.fasterxml.jackson.dataformat:jackson-dataformat-yaml:${props.getProperty('jackson')}"
- api 'org.ow2.asm:asm:9.0'
- api 'org.ow2.asm:asm-tree:9.0'
- api "org.apache.httpcomponents:httpclient:${props.getProperty('httpclient')}"
- api "org.apache.httpcomponents:httpcore:${props.getProperty('httpcore')}"
- compileOnly "com.puppycrawl.tools:checkstyle:${props.getProperty('checkstyle')}"
- testImplementation "com.puppycrawl.tools:checkstyle:${props.getProperty('checkstyle')}"
- testFixturesApi "junit:junit:${props.getProperty('junit')}"
- testFixturesApi "com.carrotsearch.randomizedtesting:randomizedtesting-runner:${props.getProperty('randomizedrunner')}"
- testFixturesApi gradleApi()
- testFixturesApi gradleTestKit()
- testImplementation 'com.github.tomakehurst:wiremock-jre8-standalone:2.23.2'
- testImplementation 'org.mockito:mockito-core:1.9.5'
- integTestImplementation('org.spockframework:spock-core:1.3-groovy-2.5') {
- exclude module: "groovy"
- }
- integTestImplementation "org.xmlunit:xmlunit-core:2.8.2"
- }
- /*****************************************************************************
- * Bootstrap repositories *
- *****************************************************************************/
- // this will only happen when buildSrc is built on its own during build init
- if (project == rootProject) {
- repositories {
- if (System.getProperty("repos.mavenLocal") != null) {
- mavenLocal()
- }
- }
- dependencies {
- // add this so the runtime classpath so Gradle will properly track it as a build runtime classpath input
- runtimeOnly project('reaper')
- }
- // only run tests as build-tools
- tasks.named("test").configure {
- enabled = false
- }
- }
- /*****************************************************************************
- * Normal project checks *
- *****************************************************************************/
- // this happens when included as a normal project in the build, which we do
- // to enforce precommit checks like forbidden apis, as well as setup publishing
- if (project != rootProject) {
- apply plugin: 'elasticsearch.build'
- apply plugin: 'elasticsearch.publish'
- // groovydoc succeeds, but has some weird internal exception...
- tasks.named("groovydoc").configure {
- enabled = false
- }
- // build-tools is not ready for primetime with these...
- tasks.named("dependencyLicenses").configure { enabled = false }
- tasks.named("dependenciesInfo").configure {enabled = false }
- tasks.named("dependenciesGraph").configure {enabled = false }
- disableTasks('forbiddenApisMain', 'forbiddenApisTest', 'forbiddenApisIntegTest', 'forbiddenApisTestFixtures')
- tasks.named("jarHell").configure {
- enabled = false
- }
- tasks.named("thirdPartyAudit").configure {
- enabled = false
- }
- configurations.register("distribution")
- configurations.register("reaper")
- dependencies {
- reaper project('reaper')
- distribution project(':distribution:archives:windows-zip')
- distribution project(':distribution:archives:darwin-tar')
- distribution project(':distribution:archives:darwin-aarch64-tar')
- distribution project(':distribution:archives:linux-aarch64-tar')
- distribution project(':distribution:archives:linux-tar')
- integTestRuntimeOnly(project(":libs:elasticsearch-core"))
- }
- eclipse {
- classpath {
- plusConfigurations += [configurations.integTestRuntimeClasspath]
- }
- }
- // for external projects we want to remove the marker file indicating we are running the Elasticsearch project
- tasks.named("processResources").configure {
- exclude 'buildSrc.marker'
- into('META-INF') {
- from configurations.reaper
- }
- }
- // Track reaper jar as a test input using runtime classpath normalization strategy
- tasks.withType(Test).configureEach {
- inputs.files(configurations.reaper).withNormalizer(ClasspathNormalizer)
- }
- normalization {
- runtimeClasspath {
- // We already include the reaper jar as part of our runtime classpath. Ignore the copy in META-INF.
- ignore('META-INF/reaper.jar')
- }
- }
- tasks.named("forbiddenPatterns").configure {
- exclude '**/*.wav'
- exclude '**/*.p12'
- exclude '**/*.jks'
- exclude '**/*.crt'
- // the file that actually defines nocommit
- exclude '**/ForbiddenPatternsTask.java'
- exclude '**/*.bcfks'
- }
- tasks.named("testingConventions") {
- naming.clear()
- naming {
- Tests {
- baseClass 'org.elasticsearch.gradle.test.GradleUnitTestCase'
- }
- IT {
- baseClass 'org.elasticsearch.gradle.test.GradleIntegrationTestCase'
- }
- }
- }
- tasks.register("integTest", Test) {
- inputs.dir(file("src/testKit")).withPropertyName("testkit dir").withPathSensitivity(PathSensitivity.RELATIVE)
- systemProperty 'test.version_under_test', version
- testClassesDirs = sourceSets.integTest.output.classesDirs
- classpath = sourceSets.integTest.runtimeClasspath
- }
- tasks.named("check").configure { dependsOn("integTest") }
- // for now we hardcode the tests for our build to use the gradle jvm.
- tasks.withType(Test).configureEach {
- onlyIf { org.elasticsearch.gradle.info.BuildParams.inFipsJvm == false }
- it.executable = Jvm.current().getJavaExecutable()
- maxParallelForks = providers.systemProperty('tests.jvms').forUseAtConfigurationTime().getOrElse(org.elasticsearch.gradle.info.BuildParams.defaultParallel.toString()) as Integer
- }
- publishing.publications.named("elastic").configure {
- suppressPomMetadataWarningsFor("testFixturesApiElements")
- suppressPomMetadataWarningsFor("testFixturesRuntimeElements")
- }
- }
- // Define this here because we need it early.
- class VersionPropertiesLoader {
- static Properties loadBuildSrcVersion(File input) throws IOException {
- Properties props = new Properties();
- InputStream is = new FileInputStream(input)
- try {
- props.load(is)
- } finally {
- is.close()
- }
- loadBuildSrcVersion(props, System.getProperties())
- return props
- }
- protected static void loadBuildSrcVersion(Properties loadedProps, Properties systemProperties) {
- String elasticsearch = loadedProps.getProperty("elasticsearch")
- if (elasticsearch == null) {
- throw new IllegalStateException("Elasticsearch version is missing from properties.")
- }
- if (elasticsearch.matches("[0-9]+\\.[0-9]+\\.[0-9]+") == false) {
- throw new IllegalStateException(
- "Expected elasticsearch version to be numbers only of the form X.Y.Z but it was: " +
- elasticsearch
- )
- }
- String qualifier = systemProperties.getProperty("build.version_qualifier", "")
- if (qualifier.isEmpty() == false) {
- if (qualifier.matches("(alpha|beta|rc)\\d+") == false) {
- throw new IllegalStateException("Invalid qualifier: " + qualifier)
- }
- elasticsearch += "-" + qualifier
- }
- final String buildSnapshotSystemProperty = systemProperties.getProperty("build.snapshot", "true");
- switch (buildSnapshotSystemProperty) {
- case "true":
- elasticsearch += "-SNAPSHOT"
- break;
- case "false":
- // do nothing
- break;
- default:
- throw new IllegalArgumentException(
- "build.snapshot was set to [" + buildSnapshotSystemProperty + "] but can only be unset or [true|false]");
- }
- loadedProps.put("elasticsearch", elasticsearch)
- }
- }
|