Fork Groovy compiler onto compile Java home

We use the --release flag which is only available starting in JDK
9. Since Gradle could be running on JDK 8 without forking the compiler,
compilation will occur with the Java home of Gradle. This commit adds a
fork flag to the compiler Java home so that we use the right compiler.

Relates #28300
This commit is contained in:
Jason Tedor 2018-01-18 12:08:32 -05:00 committed by GitHub
parent 66c81e7f5e
commit 4214a718ec
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
1 changed files with 2 additions and 0 deletions

View File

@ -459,6 +459,8 @@ class BuildPlugin implements Plugin<Project> {
// also apply release flag to groovy, which is used in build-tools
project.tasks.withType(GroovyCompile) {
final JavaVersion targetCompatibilityVersion = JavaVersion.toVersion(it.targetCompatibility)
options.fork = true
options.forkOptions.javaHome = new File(project.compilerJavaHome)
options.compilerArgs << '--release' << targetCompatibilityVersion.majorVersion
}
}