Browse Source

Fix Gradle Toolchain configuration

See gh-25787
pull/26700/head
Brian Clozel 5 years ago
parent
commit
3ab39eda08
  1. 33
      gradle/toolchains.gradle

33
gradle/toolchains.gradle

@ -28,13 +28,11 @@ @@ -28,13 +28,11 @@
*
* @author Brian Clozel
*/
def mainToolchain = 'mainToolchain'
def testToolchain = 'testToolchain'
plugins.withType(JavaPlugin) {
// Configure the Java Toolchain if the 'mainToolchain' property is defined
if (project.hasProperty(mainToolchain)) {
def mainLanguageVersion = JavaLanguageVersion.of(project.property(mainToolchain).toString())
if (project.hasProperty('mainToolchain') && project.mainToolchain) {
def mainLanguageVersion = JavaLanguageVersion.of(project.mainToolchain.toString())
java {
toolchain {
languageVersion = mainLanguageVersion
@ -48,8 +46,8 @@ plugins.withType(JavaPlugin) { @@ -48,8 +46,8 @@ plugins.withType(JavaPlugin) {
}
}
// Configure a specific Java Toolchain for compiling and running tests if the 'testToolchain' property is defined
if (project.hasProperty(testToolchain)) {
def testLanguageVersion = JavaLanguageVersion.of(project.property(testToolchain).toString());
if (project.hasProperty('testToolchain') && project.testToolchain) {
def testLanguageVersion = JavaLanguageVersion.of(project.testToolchain.toString());
tasks.withType(JavaCompile).matching { it.name.contains("Test") }.configureEach {
javaCompiler = javaToolchains.compilerFor {
languageVersion = testLanguageVersion
@ -65,7 +63,7 @@ plugins.withType(JavaPlugin) { @@ -65,7 +63,7 @@ plugins.withType(JavaPlugin) {
plugins.withType(GroovyPlugin) {
// Fallback to JDK8
if (!project.hasProperty(mainToolchain)) {
if (!project.hasProperty('mainToolchain')) {
compileGroovy {
sourceCompatibility = JavaVersion.VERSION_1_8
}
@ -74,8 +72,8 @@ plugins.withType(GroovyPlugin) { @@ -74,8 +72,8 @@ plugins.withType(GroovyPlugin) {
// Configure the Kotlin compiler if the 'mainToolchain' property is defined
pluginManager.withPlugin("kotlin") {
if (project.hasProperty(mainToolchain)) {
def mainLanguageVersion = JavaLanguageVersion.of(project.property(mainToolchain).toString());
if (project.hasProperty('mainToolchain') && project.mainToolchain) {
def mainLanguageVersion = JavaLanguageVersion.of(project.mainToolchain.toString());
def compiler = javaToolchains.compilerFor {
languageVersion = mainLanguageVersion
}
@ -96,15 +94,21 @@ pluginManager.withPlugin("kotlin") { @@ -96,15 +94,21 @@ pluginManager.withPlugin("kotlin") {
}
}
else {
// Fallback to JDK8
compileKotlin {
kotlinOptions {
jvmTarget = '1.8'
}
}
compileTestKotlin {
kotlinOptions {
jvmTarget = '1.8'
}
}
}
if (project.hasProperty(testToolchain)) {
def testLanguageVersion = JavaLanguageVersion.of(project.property(testToolchain).toString());
if (project.hasProperty('testToolchain') && project.testToolchain) {
def testLanguageVersion = JavaLanguageVersion.of(project.testToolchain.toString());
def compiler = javaToolchains.compilerFor {
languageVersion = testLanguageVersion
}
@ -117,11 +121,4 @@ pluginManager.withPlugin("kotlin") { @@ -117,11 +121,4 @@ pluginManager.withPlugin("kotlin") {
}
}
}
else {
compileTestKotlin {
kotlinOptions {
jvmTarget = '1.8'
}
}
}
}
Loading…
Cancel
Save