mirror of
https://github.com/honeymoose/OpenSearch.git
synced 2025-02-17 02:14:54 +00:00
Fail early on JDK with compiler bug
Early versions of JDK 8 have a compiler bug that prevents assignment to a definitely unassigned final variable inside the body of a lambda. This commit adds an early-out to the build process which also gives a useful error message. Closes #16418
This commit is contained in:
parent
3c7f578010
commit
6707a89c3b
@ -78,15 +78,17 @@ class BuildPlugin implements Plugin<Project> {
|
||||
if (project.rootProject.ext.has('buildChecksDone') == false) {
|
||||
String javaHome = findJavaHome()
|
||||
File gradleJavaHome = Jvm.current().javaHome
|
||||
String gradleJavaVersionDetails = "${System.getProperty('java.vendor')} ${System.getProperty('java.version')}" +
|
||||
String javaVendor = System.getProperty('java.vendor')
|
||||
String javaVersion = System.getProperty('java.version')
|
||||
String gradleJavaVersionDetails = "${javaVendor} ${javaVersion}" +
|
||||
" [${System.getProperty('java.vm.name')} ${System.getProperty('java.vm.version')}]"
|
||||
|
||||
String javaVersionDetails = gradleJavaVersionDetails
|
||||
String javaVersion = System.getProperty('java.version')
|
||||
JavaVersion javaVersionEnum = JavaVersion.current()
|
||||
if (new File(javaHome).canonicalPath != gradleJavaHome.canonicalPath) {
|
||||
javaVersionDetails = findJavaVersionDetails(project, javaHome)
|
||||
javaVersionEnum = JavaVersion.toVersion(findJavaSpecificationVersion(project, javaHome))
|
||||
javaVendor = findJavaVendor(project, javaHome)
|
||||
javaVersion = findJavaVersion(project, javaHome)
|
||||
}
|
||||
|
||||
@ -114,6 +116,25 @@ class BuildPlugin implements Plugin<Project> {
|
||||
throw new GradleException("Java ${minimumJava} or above is required to build Elasticsearch")
|
||||
}
|
||||
|
||||
// this block of code detecting buggy JDK 8 compiler versions can be removed when minimum Java version is incremented
|
||||
assert minimumJava == JavaVersion.VERSION_1_8 : "Remove JDK compiler bug detection only applicable to JDK 8"
|
||||
if (javaVersionEnum == JavaVersion.VERSION_1_8) {
|
||||
if (Objects.equals("Oracle Corporation", javaVendor)) {
|
||||
def matcher = javaVersion =~ /1\.8\.0(?:_(\d+))?/
|
||||
if (matcher.matches()) {
|
||||
int update;
|
||||
if (matcher.group(1) == null) {
|
||||
update = 0
|
||||
} else {
|
||||
update = matcher.group(1).toInteger()
|
||||
}
|
||||
if (update < 40) {
|
||||
throw new GradleException("JDK ${javaVendor} ${javaVersion} has compiler bug JDK-8052388, update your JDK to at least 8u40")
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
project.rootProject.ext.javaHome = javaHome
|
||||
project.rootProject.ext.javaVersion = javaVersion
|
||||
project.rootProject.ext.buildChecksDone = true
|
||||
@ -153,6 +174,11 @@ class BuildPlugin implements Plugin<Project> {
|
||||
return runJavascript(project, javaHome, versionScript)
|
||||
}
|
||||
|
||||
private static String findJavaVendor(Project project, String javaHome) {
|
||||
String vendorScript = 'print(java.lang.System.getProperty("java.vendor"));'
|
||||
return runJavascript(project, javaHome, vendorScript)
|
||||
}
|
||||
|
||||
/** Finds the parsable java specification version */
|
||||
private static String findJavaVersion(Project project, String javaHome) {
|
||||
String versionScript = 'print(java.lang.System.getProperty("java.version"));'
|
||||
|
Loading…
x
Reference in New Issue
Block a user