Skip to content

Commit bcee920

Browse files
committed
Refactor Java home
1 parent 30dbcb4 commit bcee920

File tree

1 file changed

+8
-12
lines changed

1 file changed

+8
-12
lines changed

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

Lines changed: 8 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -167,28 +167,24 @@ class BuildPlugin implements Plugin<Project> {
167167
project.ext.runtimeJavaVersion = project.rootProject.ext.runtimeJavaVersion
168168
}
169169

170-
/** Finds and enforces JAVA_HOME is set */
171170
private static String findCompilerJavaHome() {
172-
return findJavaHome(System.getenv('JAVA_HOME'), null)
173-
}
174-
175-
private static String findRuntimeJavaHome(final String compilerJavaHome) {
176-
return findJavaHome(System.getenv('RUNTIME_JAVA_HOME'), compilerJavaHome)
177-
}
178-
179-
private static String findJavaHome(String maybeJavaHome, String defaultJavaHome) {
180-
final String javaHome = maybeJavaHome ?: defaultJavaHome
171+
final String javaHome = System.getenv('JAVA_HOME')
181172
if (javaHome == null) {
182173
if (System.getProperty("idea.active") != null || System.getProperty("eclipse.launcher") != null) {
183174
// IntelliJ does not set JAVA_HOME, so we use the JDK that Gradle was run with
184-
javaHome = Jvm.current().javaHome
175+
return Jvm.current().javaHome
185176
} else {
186-
assert false
177+
throw new GradleException("JAVA_HOME must be set to build Elasticsearch")
187178
}
188179
}
189180
return javaHome
190181
}
191182

183+
private static String findRuntimeJavaHome(final String compilerJavaHome) {
184+
assert compilerJavaHome != null
185+
return System.getenv('RUNTIME_JAVA_HOME') ?: compilerJavaHome
186+
}
187+
192188
/** Finds printable java version of the given JAVA_HOME */
193189
private static String findJavaVersionDetails(Project project, String javaHome) {
194190
String versionInfoScript = 'print(' +

0 commit comments

Comments
 (0)