Configure Gradle's toolchain when Gradle does not handle the requested Java version
See original GitHub issueSteps to reproduce
- Select the following properties on https://start.spring.io/:
- Project: Gradle Project
- Language: Java
- Spring Boot: 2.4.5
- Java: 16
- Generate project
Behavior
When I try to build the project with ./gradlew assemble
Java 16, it fails:
> startup failed:
General error during semantic analysis: Unsupported class file major version 60
java.lang.IllegalArgumentException: Unsupported class file major version 60
It seems that the generated project contains a build.gradle
file with sourceCompatibility = '11'
. Also, the project has Gradle version 6.8.3
which does not support Java 16 out of the box and the project does not use Gradle toolchain
.
Issue Analytics
- State:
- Created 2 years ago
- Comments:10 (10 by maintainers)
Top Results From Across the Web
Toolchains for JVM projects - Gradle User Manual
By default, Gradle uses the same Java version for running Gradle itself and building JVM projects. This is not always desirable. Building projects...
Read more >Add support for Java Toolchain to the Gradle plugin : KT-43095
The issue in my case simply seems to be that Gradle toolchain support allows to configure the Java version to use for compilation,...
Read more >How do I specify the required Java version in a Gradle build?
I get the following exception: "Unable to download toolchain. This might indicate that the combination (version, architecture, release/early ...
Read more >Gradle version 2.10 is required. Current version is 4.0.1.
I can't build for android with gradle it says that I'm using the wrong ... gradles version in Unity force us to create...
Read more >Using Gradle Extra Properties Extension to Configure Git ...
Configuring git submodules on a Gradle Android project can be painful when ... Minimum required is 25.0.0 <a href="fix.build.tools.version">Update Build ...
Read more >Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start FreeTop Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found
Top GitHub Comments
The way I see it:
That looks fairly analogous to me. And a far better developer experience OOTB, at least IMO.
I’ve been using toolchains for quite some time now and in practice it has never downloaded a JDK for me, because it will pick up the appropriate JDK from my local SDKMAN installation.
Additionally, you might also take into consideration that for some time now Gradle promotes toolchains as the way of declaring Java version (see the very first snippet from the Building Java & JVM projects page of the user manual) and that
sourceCompatibility
andtargetCompatibility
are referred to as historical options for the Java compiler.From today’s standpoint, would you be open to configure Gradle’s toolchain by default, as originally proposed in #1187?
There are numerous benefits of using Gradle toolchain on top of the case expressed in this issue. A project that configures toolchain is ensured to always build using the appropriate Java version. With the ecosystem becoming increasingly split between 3 different Java version (8, 11 & 17) this feature just becomes more attractive.
Isn’t this basically the same as with the Gradle wrapper itself? You still use the wrapper in generated projects even though some environments might be more prohibitive about it and prefer to use their own Gradle distribution. Personally I wouldn’t conflate such considerations with initializr.