I have a multi project build, and I need one project to use Java 8 when the rest use Java 6 (I know but at the moment I am unable to upgrade them all)
Is there any way to have a different version of Java for one sub-project in a multi-project build?
Thanks
Gradle 6.7 introduced toolchains support. Though this was primarily defined to allow specifying the Java version a project is compiled with independent of the Java version a Gradle build is executed with, it can be used to specify different Java versions for different sub projects of a multi-module project.
For instance, given two sub projects a and b, if we want to specify that a should compile with Java 11 and b with Java 17, your builds scripts would contain the following:
project a build.gradle
java {
toolchain {
languageVersion = JavaLanguageVersion.of(11)
}
}
project b build.gradle
java {
toolchain {
languageVersion = JavaLanguageVersion.of(17)
}
}
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With