diff --git a/buildSrc/src/main/groovy/org/elasticsearch/gradle/BuildPlugin.groovy b/buildSrc/src/main/groovy/org/elasticsearch/gradle/BuildPlugin.groovy index 50e1cd68523d5..444f2283be4e7 100644 --- a/buildSrc/src/main/groovy/org/elasticsearch/gradle/BuildPlugin.groovy +++ b/buildSrc/src/main/groovy/org/elasticsearch/gradle/BuildPlugin.groovy @@ -97,6 +97,12 @@ class BuildPlugin implements Plugin { String compilerJavaHome = findCompilerJavaHome() String runtimeJavaHome = findRuntimeJavaHome(compilerJavaHome) File gradleJavaHome = Jvm.current().javaHome + + final Map javaVersions = [:] + for (int version = 7; version <= Integer.parseInt(minimumCompilerVersion.majorVersion); version++) { + javaVersions.put(version, findJavaHome(version)); + } + String javaVendor = System.getProperty('java.vendor') String javaVersion = System.getProperty('java.version') String gradleJavaVersionDetails = "${javaVendor} ${javaVersion}" + @@ -158,10 +164,32 @@ class BuildPlugin implements Plugin { throw new GradleException(message) } + for (final Map.Entry javaVersionEntry : javaVersions.entrySet()) { + final String javaHome = javaVersionEntry.getValue() + if (javaHome == null) { + continue + } + JavaVersion javaVersionEnum = JavaVersion.toVersion(findJavaSpecificationVersion(project, javaHome)) + final JavaVersion expectedJavaVersionEnum + final int version = javaVersionEntry.getKey() + if (version < 9) { + expectedJavaVersionEnum = JavaVersion.toVersion("1." + version) + } else { + expectedJavaVersionEnum = JavaVersion.toVersion(Integer.toString(version)) + } + if (javaVersionEnum != expectedJavaVersionEnum) { + final String message = + "the environment variable JAVA" + version + "_HOME must be set to a JDK installation directory for Java" + + " ${expectedJavaVersionEnum} but is [${javaHome}] corresponding to [${javaVersionEnum}]" + throw new GradleException(message) + } + } + project.rootProject.ext.compilerJavaHome = compilerJavaHome project.rootProject.ext.runtimeJavaHome = runtimeJavaHome project.rootProject.ext.compilerJavaVersion = compilerJavaVersionEnum project.rootProject.ext.runtimeJavaVersion = runtimeJavaVersionEnum + project.rootProject.ext.javaVersions = javaVersions project.rootProject.ext.buildChecksDone = true } @@ -173,6 +201,7 @@ class BuildPlugin implements Plugin { project.ext.runtimeJavaHome = project.rootProject.ext.runtimeJavaHome project.ext.compilerJavaVersion = project.rootProject.ext.compilerJavaVersion project.ext.runtimeJavaVersion = project.rootProject.ext.runtimeJavaVersion + project.ext.javaVersions = project.rootProject.ext.javaVersions } private static String findCompilerJavaHome() { @@ -188,6 +217,10 @@ class BuildPlugin implements Plugin { return javaHome } + private static String findJavaHome(int version) { + return System.getenv('JAVA' + version + '_HOME') + } + private static String findRuntimeJavaHome(final String compilerJavaHome) { assert compilerJavaHome != null return System.getenv('RUNTIME_JAVA_HOME') ?: compilerJavaHome diff --git a/buildSrc/src/main/groovy/org/elasticsearch/gradle/test/NodeInfo.groovy b/buildSrc/src/main/groovy/org/elasticsearch/gradle/test/NodeInfo.groovy index 16c1b58837162..9e0a4b2554b4b 100644 --- a/buildSrc/src/main/groovy/org/elasticsearch/gradle/test/NodeInfo.groovy +++ b/buildSrc/src/main/groovy/org/elasticsearch/gradle/test/NodeInfo.groovy @@ -22,7 +22,9 @@ import com.sun.jna.Native import com.sun.jna.WString import org.apache.tools.ant.taskdefs.condition.Os import org.elasticsearch.gradle.Version +import org.gradle.api.GradleException import org.gradle.api.InvalidUserDataException +import org.gradle.api.JavaVersion import org.gradle.api.Project import java.nio.file.Files @@ -162,7 +164,25 @@ class NodeInfo { args.add("${esScript}") } - env = ['JAVA_HOME': project.runtimeJavaHome] + final String javaHome + final Map javaVersions = project.javaVersions + if (Version.fromString(nodeVersion).before("6.2.0")) { + final String java8Home = javaVersions.get(8) + if (java8Home == null) { + throw new GradleException("JAVA8_HOME must be set to run BWC tests against [" + nodeVersion + "]") + } + javaHome = java8Home + } else if (Version.fromString(nodeVersion).onOrAfter("6.2.0") && Version.fromString(nodeVersion).before("6.3.0")) { + final String java9Home = javaVersions.get(9) + if (java9Home == null) { + throw new GradleException("JAVA9_HOME must be set to run BWC tests against [" + nodeVersion + "]") + } + javaHome = java9Home + } else { + javaHome = project.compilerJavaHome + } + + env = ['JAVA_HOME':javaHome] args.addAll("-E", "node.portsfile=true") String collectedSystemProperties = config.systemProperties.collect { key, value -> "-D${key}=${value}" }.join(" ") String esJavaOpts = config.jvmArgs.isEmpty() ? collectedSystemProperties : collectedSystemProperties + " " + config.jvmArgs diff --git a/distribution/bwc/build.gradle b/distribution/bwc/build.gradle index 0227184380563..eea0c3952b57d 100644 --- a/distribution/bwc/build.gradle +++ b/distribution/bwc/build.gradle @@ -144,12 +144,19 @@ subprojects { task buildBwcVersion(type: Exec) { dependsOn checkoutBwcBranch, writeBuildMetadata workingDir = checkoutDir - if (project.rootProject.ext.runtimeJavaVersion == JavaVersion.VERSION_1_8 && ["5.6", "6.0", "6.1"].contains(bwcBranch)) { - /* - * If runtime Java home is set to JDK 8 and we are building branches that are officially built with JDK 8, push this to JAVA_HOME for - * these builds. - */ - environment('JAVA_HOME', System.getenv('RUNTIME_JAVA_HOME')) + if (["5.6", "6.0", "6.1"].contains(bwcBranch)) { + // we are building branches that are officially built with JDK 8, push JAVA8_HOME to JAVA_HOME for these builds + if (project.javaVersions.get(8) == null) { + throw new GradleException("JAVA8_HOME is required to build BWC versions for BWC branch [" + bwcBranch + "]") + } + environment('JAVA_HOME', project.javaVersions.get(8)) + } else if ("6.2".equals(bwcBranch)) { + if (project.javaVersions.get(9) == null) { + throw new GradleException("JAVA9_HOME is required to build BWC versions for BWC branch [" + bwcBranch + "]") + } + environment('JAVA_HOME', project.javaVersions.get(9)) + } else { + environment('JAVA_HOME', project.compilerJavaHome) } if (Os.isFamily(Os.FAMILY_WINDOWS)) { executable 'cmd' diff --git a/qa/reindex-from-old/build.gradle b/qa/reindex-from-old/build.gradle index c9388c42bf54a..4fe481543c336 100644 --- a/qa/reindex-from-old/build.gradle +++ b/qa/reindex-from-old/build.gradle @@ -51,11 +51,13 @@ dependencies { es090 'org.elasticsearch:elasticsearch:0.90.13@zip' } -if (project.runtimeJavaVersion >= JavaVersion.VERSION_1_9 || Os.isFamily(Os.FAMILY_WINDOWS)) { - /* We can't run the dependencies with Java 9 so for now we'll skip the whole - * thing. We can't get the pid files in windows so we skip that as well.... */ +if (Os.isFamily(Os.FAMILY_WINDOWS)) { + // we can't get the pid files in windows so we skip that integTest.enabled = false } else { + if (project.javaVersions.get(7) == null) { + throw new GradleException("JAVA7_HOME must be set to run reindex-from-old") + } /* Set up tasks to unzip and run the old versions of ES before running the * integration tests. */ for (String version : ['2', '1', '090']) { @@ -75,7 +77,7 @@ if (project.runtimeJavaVersion >= JavaVersion.VERSION_1_9 || Os.isFamily(Os.FAMI dependsOn unzip executable = new File(project.runtimeJavaHome, 'bin/java') env 'CLASSPATH', "${ -> project.configurations.oldesFixture.asPath }" - env 'JAVA_HOME', project.runtimeJavaHome + env 'JAVA_HOME', project.javaVersions.get(7) args 'oldes.OldElasticsearch', baseDir, unzip.temporaryDir,