-
Notifications
You must be signed in to change notification settings - Fork 1.7k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Configure Gradle's toolchains #1227
Comments
start.spring.io is doing its best here to accommodate your request. Spring Boot 2.4.x only supports Gradle 6.x and Gradle 6.x does not support Java 16. As a result, the Java version that you have selected has been downgraded to a version that Gradle 6.8.x does support. If you want to use Java 16 with Spring Boot 2.4.5 and Gradle, then, as you have noted, you can configure Gradle's toolchain support. We considered making start.spring.io do this automatically but decided against it as it may lead to some surprising behaviour as, for example, it can cause Gradle to download a JDK which may be blocked or prohibited for some users. I wonder if we could/should add an entry to |
There is one, actually:
The explanation however, isn't great. Isn't this a duplicate of spring-io/start.spring.io#250 ? |
I'd forgotten about spring-io/start.spring.io#250. Thanks for the reminder, @snicoll. I think this could well be a duplicate. An alternative would be for us to treat this a little bit differently. For example, we could generate the project with Gradle 6.8.3 and Another alternative would be to reconsider our concerns and configure the toolchain by default after all, with a note in HELP.md highlighting what has been done. |
Honoring the user's choice and generate a broken project with a note in HELP.md does not sound very appealing to me. If they really want to run on a version that the version of Spring Boot they've chosen is not supported, they could change back the value to 16 and follow that notes about configuring toolchain. I think this one has the advantage of being more explicit (i.e. failing only if you start using Java 12+ APIs). |
I think it could be argued that the current behaviour is also broken, albeit silently. The user's asked for something that we could configure for them, but we've given them something else instead. This is why I suggested the second alternative where we configure the toolchain. I think I'm leaning towards this approach now. It's giving the user exactly what they've asked for within the limitations of Gradle 6.x. |
Yup, not denying the problem, just giving feedback on the first solution and forgetting to provide some for the other one :) What you said. If configuring the toolchain is easy enough, I'd like us to explore that option and add a note in HELP.md perhaps? |
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. |
No, I didn't think so. You can avoid using the wrapper with changing the build script by running |
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 |
As I read it, In short, there’s no perfect one-size-fits-all solution here. There are numerous options, each with slightly different advantages and disadvantages, particularly when you consider that we also have to support Java 8. |
Why not toolchains by default? I think they are awesome. |
Please see the discussion above, particularly this comment and the issue to which it links. |
This commit improves the resolution of plugins to ignore a non fatal resolution of the model. See gh-1227
Just tested with Gradle 8.7: The automatic download of JDKs is not enabled by default. If you request a Java version through a toolchain which is not available on the machine, it fails with:
To automatically download JDKs, the user has to specify toolchain download repositories. |
That's a really nice improvement. Looks like it landed in Gradle 8.0. Given that it removes one of the downsides of the toolchains approach, I'm in favour of this now for cases where the Gradle version and the Java version are not compatible. Right now, we'd use a toolchain for Gradle projects that are using Java 22. When we upgrade to Gradle 8.8, we'd switch it off again. |
We talked about that in our meeting and want to make toolchains the default. If that leads to problems, we'll just use them if we need to, e.g. compiling Java 22 with Gradle 8.7. |
This is obsolete when using toolchains. The Kotlin plugin automatically sets the jvmTarget to the used toolchain. See gh-1227
Steps to reproduce
Behavior
When I try to build the project with
./gradlew assemble
Java 16, it fails:It seems that the generated project contains a
build.gradle
file withsourceCompatibility = '11'
. Also, the project has Gradle version6.8.3
which does not support Java 16 out of the box and the project does not use Gradletoolchain
.The text was updated successfully, but these errors were encountered: