Luis Mirabal
07/04/2024, 12:26 PMsourceCompatibility and targetCompatibility? Or would gradle take it from the toolchain version?Vampire
07/04/2024, 12:49 PMLuis Mirabal
07/04/2024, 12:50 PMVampire
07/04/2024, 12:52 PMVampire
07/04/2024, 12:52 PMVampire
07/04/2024, 12:53 PMMartin
07/04/2024, 1:46 PMoptions.release and latest JVM (no toolchain). See also https://jakewharton.com/gradle-toolchains-are-rarely-a-good-idea/Vampire
07/04/2024, 2:02 PM-release.
And if you want to stay on the cutting edge of Java versions, then usually using a newly released Java version is usable via toolchains a few versions before it is supported to run Gradle with that version.
...
Like always, both approaches have their pros and cons.
But that blog article is very contra, not looking at both sides of the medal.Martin
07/04/2024, 2:04 PMLuis Mirabal
07/04/2024, 2:05 PMMartin
07/04/2024, 2:06 PMVampire
07/04/2024, 2:07 PMJAVA_HOME to a version that is needed to run that build.
...Martin
07/04/2024, 2:12 PMWhy not?More disk space, more heap space to allocate, no sharing of the JVM caches, etc...
you for example want to compile your code with Java 22, but Gradle 8.8 is not released yetYup 👍 Fair use case. Although that’s good incentive to move the ecosystem forward. I haven’t been blocked by this yet (I compile for Java 8 mostly 😅 )
with JVM toolchains it will just build as expected for everyone trying to run the build as long as he runs Gradle with a Java version that is compatibleAgreed but as said above, I prefer to do this higher up in the Gradle wrapper itself (which is doable now 🎉 )
Vampire
07/04/2024, 2:17 PMMore disk spaceNot really. When you need to build 10 projects with 10 different JVMs you still need those JVMs and thus the space.
more heap space to allocateWhere? Why?
no sharing of the JVM cachesWhich caches? Why?
which is doable nowNot that good so far, for example no auto-provisioning, only already available version can be used. But promising, yes. But even with that, I very much like the Java version used to run Gradle separated from the Java version used to build and run my code. They are just totally different and have totally different requirements.
Martin
07/04/2024, 2:18 PMMartin
07/04/2024, 2:19 PMMartin
07/04/2024, 2:20 PMMartin
07/04/2024, 2:21 PMVampire
07/04/2024, 2:21 PMI also expect that a single JVM with a huge heap can control its GC much better than multiple JVMsYou have multiple JVMs either way. Gradle starts various worker daemons / compiler daemons / test execution daemons / ... The question is just which JVM is used for them, the one also used to run Gradle or another one. But either way it will be a sperate process.
Martin
07/04/2024, 2:21 PMMartin
07/04/2024, 2:22 PMVampire
07/04/2024, 2:22 PMMartin
07/04/2024, 2:23 PMMartin
07/04/2024, 2:24 PMno auto-provisioning, only already available version can be used.Definitely agree on this one. Would love to get auto-provisioning. And a wrapper that doesn’t require Java preinstalled. That’d be a huge boost for adoption
Philip W
07/04/2024, 2:25 PMCould I run my javac task in-process?Are you sure this will work with different classpaths?
Martin
07/04/2024, 2:26 PMMartin
07/04/2024, 2:26 PMMartin
07/04/2024, 2:27 PMVampire
07/04/2024, 2:29 PMMartin
07/04/2024, 2:32 PMVampire
07/04/2024, 2:33 PMMartin
07/04/2024, 2:33 PMMartin
07/04/2024, 2:34 PM-Xmx inflation for many teams...)Martin
07/04/2024, 2:34 PMosip
07/17/2024, 10:33 AM--release compiler flag wouldn’t be a good idea?
____________
Answer: It is allowed to use toolchains and specify options.release for compilation tasksThomas Broyer
07/17/2024, 12:42 PMVampire
07/17/2024, 12:48 PMsourceCompatibility and targetCompatibility, which corresponds to -source and -target.
This you can surely do:
java {
toolchain {
languageVersion = JavaLanguageVersion.of(11)
}
}
tasks.compileJava {
options.release = 8
}
But you could as well just use java language version 8 for the toolchain, unless you hit some bug in the Java 8 compiler or for some other reason need the newer compiler.
You can also do
java {
toolchain {
languageVersion = JavaLanguageVersion.of(11)
}
}
tasks.compileJava {
sourceCompatibility = "8"
}
But this would have the same problems you have when using -source and -target instead of --release which is always preferable.
This also works, but again has the problem of not using --release but -source and -target.
java {
toolchain {
languageVersion = JavaLanguageVersion.of(11)
}
sourceCompatibility = JavaVersion.VERSION_1_8
}
I actually thought the latter would cause some validation failure by Gradle.
Must be some other combination that was illegal.osip
07/17/2024, 1:24 PM