Hello! I’m maintaining some Gradle-based projects that still support Java 8. Until now, our CI consisted of one CI job per supported LTS Java version (8, 11, 17, 21), with each job running the entire build using that Java version.
This setup is no longer possible with Gradle 9, because Gradle itself requires at least Java 17. But according to the docs, Gradle can run on a newer JVM while still using a Java 8 JDK to compile and test the project. So I’m looking for a CLI option or Gradle property to set the build/test JDK independently from the JRE used for running Gradle. The Gradle property org.gradle.java.home looked right at first, but in my tests, that affects both the Gradle JRE and the build/test JDK.
The docs explain many different ways to set a specific Java version in the build.gradle, using toolchain options, but that’s not what I want to do. I only want to override the JDK for one build, not hardcode a fixed version into the build.gradle. I suppose I can define my own project property to allow changing the toolchain version dynamically:
if (project.hasProperty("jdkVersion")) {
java {
toolchain {
languageVersion = JavaLanguageVersion.of(project.ext.jdkVersion)
}
}
}
but I would like to know if there’s a standard solution for this, to avoid having to copy this custom code into every project.