I wonder how people selects Java version for Gradle…
During the upgrade to Spring Boot 6.0 I discovered Spring guys put hard dependency for Java 17 to Gradle if you want to load Boot Gradle plugin!
Now there are options:
- to load Gradle with latest Java at the moment, so bytecode of any lib will be accepted.
- update env var
JAVA_HOME
- update
org.gradle.java.home
in~/.gradle/gradle.properties
I think about the first as the most convenient, except that legacy build of Java 8 / Java 11 need to be rewritten to use new Gradle’s concept: toolchains ((
I never used SDKMan, nor Jabba / Asdf so cannot tell how well it integrates with Gradle in case of Java switching.
There is no problem to set Java version in Idea. I suffered only in Bash.
For Cygwin / mintty / Bash I updated my utility:
http://hg.defun.work/utils/file/tip/misc/mygradle.bash
that extract a number from the symlinks (like mygradle17
) and searches for Java path in ~/.m2/toolchains.xml
then set JAVA_HOME env var and exec
to Gradle, so the final user contract looks like:
mygradle8 bootJar
mygradle11 help
mygradle17 tasks
Note that toolchains are not the answer, as the question is not about compiling but invoking Gradle itself with the correct runtime + about support of legacy scripts.