From 13ca942152c611b2c44689e226cdfdf00b59e71a Mon Sep 17 00:00:00 2001 From: Alpar Torok Date: Thu, 25 Oct 2018 10:03:23 +0300 Subject: [PATCH] Switch build-tools to latest target version (#34746) - we already require Java 11 to build, yet we target the minimum supported version in build-tools ( currently 8 ) - this is because we have some checks that are executed in a new JVM which could be running the minimum version. - For everything else it would be nice to be able to use new features, like the new process API. With this change, we selectively compile the few classes that need an older target version and move everything over to Java 10. Unfortunately the current Gradle version does not support 11 as a target version yet. --- buildSrc/build.gradle | 55 ++++++++++++++----- .../elasticsearch/gradle/JdkJarHellCheck.java | 0 .../test/NamingConventionsCheck.java | 0 3 files changed, 41 insertions(+), 14 deletions(-) rename buildSrc/src/main/{java => minimumRuntime}/org/elasticsearch/gradle/JdkJarHellCheck.java (100%) rename buildSrc/src/main/{java => minimumRuntime}/org/elasticsearch/test/NamingConventionsCheck.java (100%) diff --git a/buildSrc/build.gradle b/buildSrc/build.gradle index 82b1d8525b1..71828468e64 100644 --- a/buildSrc/build.gradle +++ b/buildSrc/build.gradle @@ -31,22 +31,12 @@ if (GradleVersion.current() < GradleVersion.version(minimumGradleVersion)) { throw new GradleException("Gradle ${minimumGradleVersion}+ is required to build elasticsearch") } -if (JavaVersion.current() < JavaVersion.VERSION_1_8) { - throw new GradleException('Java 1.8 is required to build elasticsearch gradle tools') -} - 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' } -// Make sure :buildSrc: doesn't generate classes incompatible with RUNTIME_JAVA_HOME -// We can't use BuildPlugin here, so read from file -String minimumRuntimeVersion = file('src/main/resources/minimumRuntimeVersion').text.trim() -targetCompatibility = minimumRuntimeVersion -sourceCompatibility = minimumRuntimeVersion - /***************************************************************************** * Propagating version.properties to the rest of the build * *****************************************************************************/ @@ -82,6 +72,45 @@ processResources { from tempPropertiesFile } + +if (JavaVersion.current() < JavaVersion.VERSION_1_10) { + throw new GradleException('At least Java 10 is required to build elasticsearch gradle tools') +} + +/***************************************************************************** + * Java version * + *****************************************************************************/ + +// Gradle 4.10 does not support setting this to 11 yet +targetCompatibility = "10" +sourceCompatibility = "10" + +// We have a few classes that need to be compiled for older java versions because these are used to run checks against +// those +sourceSets { + minimumRuntime { + // We only want Java here, but the Groovy doesn't configure javadoc correctly if we don't define this as groovy + groovy { + srcDirs = ['src/main/minimumRuntime'] + } + } +} +compileMinimumRuntimeGroovy { + // We can't use BuildPlugin here, so read from file + String minimumRuntimeVersion = file('src/main/resources/minimumRuntimeVersion').text.trim() + targetCompatibility = minimumRuntimeVersion + sourceCompatibility = minimumRuntimeVersion +} +dependencies { + compile sourceSets.minimumRuntime.output + minimumRuntimeCompile "junit:junit:${props.getProperty('junit')}" + minimumRuntimeCompile localGroovy() +} +jar { + from sourceSets.minimumRuntime.output +} + + /***************************************************************************** * Dependencies used by the entire build * *****************************************************************************/ @@ -94,10 +123,7 @@ dependencies { compile localGroovy() compile "com.carrotsearch.randomizedtesting:junit4-ant:${props.getProperty('randomizedrunner')}" compile "com.carrotsearch.randomizedtesting:randomizedtesting-runner:${props.getProperty('randomizedrunner')}" - - compile("junit:junit:${props.getProperty('junit')}") { - transitive = false - } + compile 'com.netflix.nebula:gradle-extra-configurations-plugin:3.0.3' compile 'com.netflix.nebula:nebula-publishing-plugin:4.4.4' compile 'com.netflix.nebula:gradle-info-plugin:3.0.3' @@ -156,6 +182,7 @@ if (project != rootProject) { dependenciesInfo.enabled = false forbiddenApisMain.enabled = false forbiddenApisTest.enabled = false + forbiddenApisMinimumRuntime.enabled = false jarHell.enabled = false thirdPartyAudit.enabled = false diff --git a/buildSrc/src/main/java/org/elasticsearch/gradle/JdkJarHellCheck.java b/buildSrc/src/main/minimumRuntime/org/elasticsearch/gradle/JdkJarHellCheck.java similarity index 100% rename from buildSrc/src/main/java/org/elasticsearch/gradle/JdkJarHellCheck.java rename to buildSrc/src/main/minimumRuntime/org/elasticsearch/gradle/JdkJarHellCheck.java diff --git a/buildSrc/src/main/java/org/elasticsearch/test/NamingConventionsCheck.java b/buildSrc/src/main/minimumRuntime/org/elasticsearch/test/NamingConventionsCheck.java similarity index 100% rename from buildSrc/src/main/java/org/elasticsearch/test/NamingConventionsCheck.java rename to buildSrc/src/main/minimumRuntime/org/elasticsearch/test/NamingConventionsCheck.java