question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Configure Gradle's toolchain when Gradle does not handle the requested Java version

See original GitHub issue

Steps 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:open
  • Created 2 years ago
  • Comments:10 (10 by maintainers)

github_iconTop GitHub Comments

1reaction
vpaviccommented, Jan 10, 2022

The way I see it:

  • Gradle wrapper
    • if you don’t use it you might end up using the wrong Gradle version which could fail
    • if you use it, it will download the needed Gradle version only once
  • Gradle toolchains
    • if you don’t use it you might end up using the wrong JDK version which could fail
    • if you use it, it will either pick it up from the supported locations or download the needed JDK only once

That looks fairly analogous to me. And a far better developer experience OOTB, at least IMO.

Once a project’s being configured to use a toolchain, I don’t think it’s possible to avoid using it without changing the build script.

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 and targetCompatibility are referred to as historical options for the Java compiler.

1reaction
vpaviccommented, Dec 30, 2021

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.

it can cause Gradle to download a JDK which may be blocked or prohibited for some users

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.

Read more comments on GitHub >

github_iconTop 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 >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found