-
Notifications
You must be signed in to change notification settings - Fork 37
Description
In Gradle 6.8, a new clause called toolchain was introduced that decoupled the JDK used for Gradle itself from the JDK used to compile and run the project's code. One of the limitations of this new clause is that the sourceRelease and targetRelease versions can no longer be set on the (sub)project itself, since it's forbidden by the toolchain. For example this fails:
java {
toolchain {
languageVersion = JavaLanguageVersion.of(11)
}
sourceCompatibility = JavaVersion.VERSION_1_8
targetCompatibility = JavaVersion.VERSION_1_8
}
To work around this, the source and target can be set on the JavaCompile tasks directly. For example this works:
java {
toolchain {
languageVersion = JavaLanguageVersion.of(11)
}
}
tasks.withType(JavaCompile) {
sourceCompatibility = JavaVersion.VERSION_1_8
targetCompatibility = JavaVersion.VERSION_1_8
}
I am trying to use the Java modularity plugin to compile some of my subprojects with lower target compatibilities, but using a more modern toolchain. I would like to use the mixedJavaRelease feature to compile the subproject with JDK 8, but the module-info.java with JDK 9. This works when not using the tool chain, because the source and target compatibility can be set on the factored out Gradle task. However, when using the toolchain, javamodularity tries to set source and target compatibility on the task itself, which Gradle disallows. For example this fails again:
java {
toolchain {
languageVersion = JavaLanguageVersion.of(11)
}
}
tasks.withType(JavaCompile) {
sourceCompatibility = JavaVersion.VERSION_1_8
targetCompatibility = JavaVersion.VERSION_1_8
}
modularity.mixedJavaRelease 8