Only require java<version>_home env var if needed
We accidentally started enforcing the env vars are always there. This reverts to only do this if they are requierd.
This commit is contained in:
parent
f236bb3ff6
commit
de2897a190
|
@ -116,7 +116,9 @@ class BuildPlugin implements Plugin<Project> {
|
||||||
|
|
||||||
final Map<Integer, String> javaVersions = [:]
|
final Map<Integer, String> javaVersions = [:]
|
||||||
for (int version = 7; version <= Integer.parseInt(minimumCompilerVersion.majorVersion); version++) {
|
for (int version = 7; version <= Integer.parseInt(minimumCompilerVersion.majorVersion); version++) {
|
||||||
javaVersions.put(version, findJavaHome(version.toString()));
|
if(System.getenv(getJavaHomeEnvVarName(version.toString())) != null) {
|
||||||
|
javaVersions.put(version, findJavaHome(version.toString()));
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
String javaVendor = System.getProperty('java.vendor')
|
String javaVendor = System.getProperty('java.vendor')
|
||||||
|
@ -247,8 +249,8 @@ class BuildPlugin implements Plugin<Project> {
|
||||||
}
|
}
|
||||||
|
|
||||||
private static String findJavaHome(String version) {
|
private static String findJavaHome(String version) {
|
||||||
String versionedVarName = 'JAVA' + version + '_HOME'
|
String versionedVarName = getJavaHomeEnvVarName(version)
|
||||||
String versionedJavaHome = System.getenv(versionedVarName)
|
String versionedJavaHome = System.getenv(versionedVarName);
|
||||||
if (versionedJavaHome == null) {
|
if (versionedJavaHome == null) {
|
||||||
throw new GradleException(
|
throw new GradleException(
|
||||||
"$versionedVarName must be set to build Elasticsearch. " +
|
"$versionedVarName must be set to build Elasticsearch. " +
|
||||||
|
@ -259,6 +261,10 @@ class BuildPlugin implements Plugin<Project> {
|
||||||
return versionedJavaHome
|
return versionedJavaHome
|
||||||
}
|
}
|
||||||
|
|
||||||
|
private static String getJavaHomeEnvVarName(String version) {
|
||||||
|
return 'JAVA' + version + '_HOME'
|
||||||
|
}
|
||||||
|
|
||||||
/** Add a check before gradle execution phase which ensures java home for the given java version is set. */
|
/** Add a check before gradle execution phase which ensures java home for the given java version is set. */
|
||||||
static void requireJavaHome(Task task, int version) {
|
static void requireJavaHome(Task task, int version) {
|
||||||
Project rootProject = task.project.rootProject // use root project for global accounting
|
Project rootProject = task.project.rootProject // use root project for global accounting
|
||||||
|
|
Loading…
Reference in New Issue