Skip to content

Commit 95475f9

Browse files
committed
Runtime Java home
1 parent 4be00e0 commit 95475f9

File tree

2 files changed

+12
-31
lines changed

2 files changed

+12
-31
lines changed

CONTRIBUTING.md

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -96,8 +96,9 @@ JDK 9 is required to build Elasticsearch. You must have a JDK 9 installation
9696
with the environment variable `JAVA_HOME` referencing the path to Java home for
9797
your JDK 9 installation. By default, tests use the same runtime as `JAVA_HOME`.
9898
However, since Elasticsearch, supports JDK 8 the build supports compiling with
99-
JDK 9 and testing on a JDK 8 runtime; to do this, set `JAVA_8_HOME` pointing to
100-
the Java home of a JDK 8 installation.
99+
JDK 9 and testing on a JDK 8 runtime; to do this, set `RUNTIME_JAVA_HOME`
100+
pointing to the Java home of a JDK 8 installation. Note that this mechanism can
101+
be used to test against other JDKs as well, this is not only limited to JDK 8.
101102

102103
Elasticsearch uses the Gradle wrapper for its build. You can execute Gradle
103104
using the wrapper via the `gradlew` script in the root of the repository.

buildSrc/src/main/groovy/org/elasticsearch/gradle/BuildPlugin.groovy

Lines changed: 9 additions & 29 deletions
Original file line numberDiff line numberDiff line change
@@ -94,7 +94,7 @@ class BuildPlugin implements Plugin<Project> {
9494
static void globalBuildInfo(Project project) {
9595
if (project.rootProject.ext.has('buildChecksDone') == false) {
9696
String compilerJavaHome = findCompilerJavaHome()
97-
String runtimeJavaHome = findRuntimeJavaHome(project)
97+
String runtimeJavaHome = findRuntimeJavaHome(compilerJavaHome)
9898
File gradleJavaHome = Jvm.current().javaHome
9999
String javaVendor = System.getProperty('java.vendor')
100100
String javaVersion = System.getProperty('java.version')
@@ -168,42 +168,22 @@ class BuildPlugin implements Plugin<Project> {
168168

169169
/** Finds and enforces JAVA_HOME is set */
170170
private static String findCompilerJavaHome() {
171-
String javaHome = System.getenv('JAVA_HOME')
172-
if (javaHome == null) {
173-
if (System.getProperty("idea.active") != null || System.getProperty("eclipse.launcher") != null) {
174-
// intellij doesn't set JAVA_HOME, so we use the jdk gradle was run with
175-
javaHome = Jvm.current().javaHome
176-
} else {
177-
throw new GradleException('JAVA_HOME must be set to build Elasticsearch')
178-
}
179-
}
180-
return javaHome
171+
return findJavaHome(System.getenv('JAVA_HOME'), null)
181172
}
182173

183-
private static String findRuntimeJavaHome(Project project) {
184-
String java8Home = System.getenv('JAVA_8_HOME')
185-
final String maybeJavaHome
186-
if (java8Home == null) {
187-
// if JAVA_8_HOME is not set fallback to JAVA_HOME
188-
maybeJavaHome = System.getenv('JAVA_HOME')
189-
} else {
190-
// if JAVA_8_HOME is set it must point to a JDK 8 Java home
191-
JavaVersion version = JavaVersion.toVersion(findJavaSpecificationVersion(project, java8Home))
192-
if (version.majorVersion != minimumRuntimeVersion.majorVersion) {
193-
throw new GradleException("if JAVA_8_HOME is set it must point to a JDK 8 Java home but was [" + java8Home + "]")
194-
}
195-
maybeJavaHome = java8Home
196-
}
197-
final String javaHome
198-
if (maybeJavaHome == null) {
174+
private static String findRuntimeJavaHome(final String compilerJavaHome) {
175+
return findJavaHome(System.getenv('RUNTIME_JAVA_HOME'), compilerJavaHome)
176+
}
177+
178+
private static String findJavaHome(String maybeJavaHome, String defaultJavaHome) {
179+
final String javaHome = maybeJavaHome ?: defaultJavaHome
180+
if (javaHome == null) {
199181
if (System.getProperty("idea.active") != null || System.getProperty("eclipse.launcher") != null) {
200182
// IntelliJ does not set JAVA_HOME, so we use the JDK that Gradle was run with
201183
javaHome = Jvm.current().javaHome
202184
} else {
203185
assert false
204186
}
205-
} else {
206-
javaHome = maybeJavaHome
207187
}
208188
return javaHome
209189
}

0 commit comments

Comments
 (0)