-
Notifications
You must be signed in to change notification settings - Fork 25k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Require JDK 9 for compilation #28071
Merged
Merged
Changes from 15 commits
Commits
Show all changes
19 commits
Select commit
Hold shift + click to select a range
3927581
Require JDK 9 for compilation
jasontedor b92fdf3
Update docs
jasontedor fab460e
Fix reindex from remote tests
jasontedor 4e137e5
Merge branch 'master' into compile-with-jdk-9
jasontedor 4be00e0
Merge branch 'master' into compile-with-jdk-9
jasontedor 95475f9
Runtime Java home
jasontedor c295dfa
Merge branch 'master' into compile-with-jdk-9
jasontedor 4af4f89
Merge branch 'master' into compile-with-jdk-9
jasontedor 8d33402
Use JDK 8 if available when building legacy
jasontedor 6ca2834
Merge branch 'master' into compile-with-jdk-9
jasontedor a79c2c1
Merge branch 'master' into compile-with-jdk-9
jasontedor 1269506
Merge branch 'master' into compile-with-jdk-9
jasontedor f3a76a7
Merge branch 'master' into compile-with-jdk-9
jasontedor 30dbcb4
Merge branch 'master' into compile-with-jdk-9
jasontedor bcee920
Refactor Java home
jasontedor 55d2b1b
In case 6.0 is compiled
jasontedor 9434717
Add comment on --release flag
jasontedor 6860f66
Merge branch 'master' into compile-with-jdk-9
jasontedor faef9bd
Merge branch 'master' into compile-with-jdk-9
jasontedor File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -56,7 +56,8 @@ import java.time.ZonedDateTime | |
*/ | ||
class BuildPlugin implements Plugin<Project> { | ||
|
||
static final JavaVersion minimumJava = JavaVersion.VERSION_1_8 | ||
static final JavaVersion minimumRuntimeVersion = JavaVersion.VERSION_1_8 | ||
static final JavaVersion minimumCompilerVersion = JavaVersion.VERSION_1_9 | ||
|
||
@Override | ||
void apply(Project project) { | ||
|
@@ -93,20 +94,26 @@ class BuildPlugin implements Plugin<Project> { | |
/** Performs checks on the build environment and prints information about the build environment. */ | ||
static void globalBuildInfo(Project project) { | ||
if (project.rootProject.ext.has('buildChecksDone') == false) { | ||
String javaHome = findJavaHome() | ||
String compilerJavaHome = findCompilerJavaHome() | ||
String runtimeJavaHome = findRuntimeJavaHome(compilerJavaHome) | ||
File gradleJavaHome = Jvm.current().javaHome | ||
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 | ||
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) | ||
String compilerJavaVersionDetails = gradleJavaVersionDetails | ||
JavaVersion compilerJavaVersionEnum = JavaVersion.current() | ||
if (new File(compilerJavaHome).canonicalPath != gradleJavaHome.canonicalPath) { | ||
compilerJavaVersionDetails = findJavaVersionDetails(project, compilerJavaHome) | ||
compilerJavaVersionEnum = JavaVersion.toVersion(findJavaSpecificationVersion(project, compilerJavaHome)) | ||
} | ||
|
||
String runtimeJavaVersionDetails = gradleJavaVersionDetails | ||
JavaVersion runtimeJavaVersionEnum = JavaVersion.current() | ||
if (new File(runtimeJavaHome).canonicalPath != gradleJavaHome.canonicalPath) { | ||
runtimeJavaVersionDetails = findJavaVersionDetails(project, runtimeJavaHome) | ||
runtimeJavaVersionEnum = JavaVersion.toVersion(findJavaSpecificationVersion(project, runtimeJavaHome)) | ||
} | ||
|
||
// Build debugging info | ||
|
@@ -115,11 +122,13 @@ class BuildPlugin implements Plugin<Project> { | |
println '=======================================' | ||
println " Gradle Version : ${project.gradle.gradleVersion}" | ||
println " OS Info : ${System.getProperty('os.name')} ${System.getProperty('os.version')} (${System.getProperty('os.arch')})" | ||
if (gradleJavaVersionDetails != javaVersionDetails) { | ||
if (gradleJavaVersionDetails != compilerJavaVersionDetails || gradleJavaVersionDetails != runtimeJavaVersionDetails) { | ||
println " JDK Version (gradle) : ${gradleJavaVersionDetails}" | ||
println " JAVA_HOME (gradle) : ${gradleJavaHome}" | ||
println " JDK Version (compile) : ${javaVersionDetails}" | ||
println " JAVA_HOME (compile) : ${javaHome}" | ||
println " JDK Version (compile) : ${compilerJavaVersionDetails}" | ||
println " JAVA_HOME (compile) : ${compilerJavaHome}" | ||
println " JDK Version (runtime) : ${runtimeJavaVersionDetails}" | ||
println " JAVA_HOME (runtime) : ${runtimeJavaHome}" | ||
} else { | ||
println " JDK Version : ${gradleJavaVersionDetails}" | ||
println " JAVA_HOME : ${gradleJavaHome}" | ||
|
@@ -135,54 +144,47 @@ class BuildPlugin implements Plugin<Project> { | |
} | ||
|
||
// enforce Java version | ||
if (javaVersionEnum < minimumJava) { | ||
throw new GradleException("Java ${minimumJava} or above is required to build Elasticsearch") | ||
if (compilerJavaVersionEnum < minimumCompilerVersion) { | ||
throw new GradleException("Java ${minimumCompilerVersion} 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") | ||
} | ||
} | ||
} | ||
if (runtimeJavaVersionEnum < minimumRuntimeVersion) { | ||
throw new GradleException("Java ${minimumRuntimeVersion} or above is required to run Elasticsearch") | ||
} | ||
|
||
project.rootProject.ext.javaHome = javaHome | ||
project.rootProject.ext.javaVersion = javaVersionEnum | ||
project.rootProject.ext.compilerJavaHome = compilerJavaHome | ||
project.rootProject.ext.runtimeJavaHome = runtimeJavaHome | ||
project.rootProject.ext.compilerJavaVersion = compilerJavaVersionEnum | ||
project.rootProject.ext.runtimeJavaVersion = runtimeJavaVersionEnum | ||
project.rootProject.ext.buildChecksDone = true | ||
} | ||
project.targetCompatibility = minimumJava | ||
project.sourceCompatibility = minimumJava | ||
project.targetCompatibility = minimumRuntimeVersion | ||
project.sourceCompatibility = minimumRuntimeVersion | ||
// set java home for each project, so they dont have to find it in the root project | ||
project.ext.javaHome = project.rootProject.ext.javaHome | ||
project.ext.javaVersion = project.rootProject.ext.javaVersion | ||
project.ext.compilerJavaHome = project.rootProject.ext.compilerJavaHome | ||
project.ext.runtimeJavaHome = project.rootProject.ext.runtimeJavaHome | ||
project.ext.compilerJavaVersion = project.rootProject.ext.compilerJavaVersion | ||
project.ext.runtimeJavaVersion = project.rootProject.ext.runtimeJavaVersion | ||
} | ||
|
||
/** Finds and enforces JAVA_HOME is set */ | ||
private static String findJavaHome() { | ||
String javaHome = System.getenv('JAVA_HOME') | ||
private static String findCompilerJavaHome() { | ||
final String javaHome = System.getenv('JAVA_HOME') | ||
if (javaHome == null) { | ||
if (System.getProperty("idea.active") != null || System.getProperty("eclipse.launcher") != null) { | ||
// intellij doesn't set JAVA_HOME, so we use the jdk gradle was run with | ||
javaHome = Jvm.current().javaHome | ||
// IntelliJ does not set JAVA_HOME, so we use the JDK that Gradle was run with | ||
return Jvm.current().javaHome | ||
} else { | ||
throw new GradleException('JAVA_HOME must be set to build Elasticsearch') | ||
throw new GradleException("JAVA_HOME must be set to build Elasticsearch") | ||
} | ||
} | ||
return javaHome | ||
} | ||
|
||
private static String findRuntimeJavaHome(final String compilerJavaHome) { | ||
assert compilerJavaHome != null | ||
return System.getenv('RUNTIME_JAVA_HOME') ?: compilerJavaHome | ||
} | ||
|
||
/** Finds printable java version of the given JAVA_HOME */ | ||
private static String findJavaVersionDetails(Project project, String javaHome) { | ||
String versionInfoScript = 'print(' + | ||
|
@@ -412,7 +414,7 @@ class BuildPlugin implements Plugin<Project> { | |
|
||
/** Adds compiler settings to the project */ | ||
static void configureCompile(Project project) { | ||
if (project.javaVersion < JavaVersion.VERSION_1_10) { | ||
if (project.compilerJavaVersion < JavaVersion.VERSION_1_10) { | ||
project.ext.compactProfile = 'compact3' | ||
} else { | ||
project.ext.compactProfile = 'full' | ||
|
@@ -422,7 +424,7 @@ class BuildPlugin implements Plugin<Project> { | |
File gradleJavaHome = Jvm.current().javaHome | ||
// we fork because compiling lots of different classes in a shared jvm can eventually trigger GC overhead limitations | ||
options.fork = true | ||
options.forkOptions.executable = new File(project.javaHome, 'bin/javac') | ||
options.forkOptions.javaHome = new File(project.compilerJavaHome) | ||
options.forkOptions.memoryMaximumSize = "1g" | ||
if (project.targetCompatibility >= JavaVersion.VERSION_1_8) { | ||
// compile with compact 3 profile by default | ||
|
@@ -447,22 +449,17 @@ class BuildPlugin implements Plugin<Project> { | |
|
||
options.encoding = 'UTF-8' | ||
options.incremental = true | ||
|
||
if (project.javaVersion == JavaVersion.VERSION_1_9) { | ||
// hack until gradle supports java 9's new "--release" arg | ||
assert minimumJava == JavaVersion.VERSION_1_8 | ||
options.compilerArgs << '--release' << '8' | ||
} | ||
options.compilerArgs << '--release' << project.targetCompatibility.majorVersion | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Can you add a comment to this line linking the relevant gradle issue for adding builtin support for this: gradle/gradle#2510 There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I pushed 9434717. |
||
} | ||
} | ||
} | ||
|
||
static void configureJavadoc(Project project) { | ||
project.tasks.withType(Javadoc) { | ||
executable = new File(project.javaHome, 'bin/javadoc') | ||
executable = new File(project.compilerJavaHome, 'bin/javadoc') | ||
} | ||
configureJavadocJar(project) | ||
if (project.javaVersion == JavaVersion.VERSION_1_10) { | ||
if (project.compilerJavaVersion == JavaVersion.VERSION_1_10) { | ||
project.tasks.withType(Javadoc) { it.enabled = false } | ||
project.tasks.getByName('javadocJar').each { it.enabled = false } | ||
} | ||
|
@@ -508,7 +505,7 @@ class BuildPlugin implements Plugin<Project> { | |
'X-Compile-Lucene-Version': VersionProperties.lucene, | ||
'X-Compile-Elasticsearch-Snapshot': isSnapshot, | ||
'Build-Date': ZonedDateTime.now(ZoneOffset.UTC), | ||
'Build-Java-Version': project.javaVersion) | ||
'Build-Java-Version': project.compilerJavaVersion) | ||
if (jarTask.manifest.attributes.containsKey('Change') == false) { | ||
logger.warn('Building without git revision id.') | ||
jarTask.manifest.attributes('Change': 'Unknown') | ||
|
@@ -545,7 +542,7 @@ class BuildPlugin implements Plugin<Project> { | |
/** Returns a closure of common configuration shared by unit and integration tests. */ | ||
static Closure commonTestConfig(Project project) { | ||
return { | ||
jvm "${project.javaHome}/bin/java" | ||
jvm "${project.runtimeJavaHome}/bin/java" | ||
parallelism System.getProperty('tests.jvms', 'auto') | ||
ifNoTests 'fail' | ||
onNonEmptyWorkDirectory 'wipe' | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Why was this exception changed to an assertion? Is it moved somewhere else I'm missing?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I am glad that you caught this. This was inadvertent, it arose in a refactoring I did in 95475f9 which refactored two basically identical methods from an earlier version of this pull request (
findCompilerJavaHome
andfindRuntimeJavaHome
) into one (findJavaHome
). Before the refactoring, the second method did not need such a line because by the time it had executed the first one would have already thrown that exception (hence theassert false
). When I refactored, I must have based by work onfindRuntimeJavaHome
inadvertently losing this exception. I have pushed: bcee920.