Skip to content
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

Use 'Toolchains for JVM projects' of Gradle 6.7+ #1187

Closed
KENNYSOFT opened this issue Feb 26, 2021 · 8 comments
Closed

Use 'Toolchains for JVM projects' of Gradle 6.7+ #1187

KENNYSOFT opened this issue Feb 26, 2021 · 8 comments

Comments

@KENNYSOFT
Copy link
Contributor

KENNYSOFT commented Feb 26, 2021

Gradle 6.7 introduced 'Toolchains for JVM projects'.

Reference: https://docs.gradle.org/6.8.2/userguide/toolchains.html

So my suggestion is changing sourceCompatibility to:

java {
    toolchain {
        languageVersion = JavaLanguageVersion.of(generation)
    }
}

@Override
protected void writeJavaSourceCompatibility(IndentingWriter writer, GradleBuildSettings settings) {
writeProperty(writer, "sourceCompatibility", settings.getSourceCompatibility());
}

@Override
protected void writeJavaSourceCompatibility(IndentingWriter writer, GradleBuildSettings settings) {
writer.println("java.sourceCompatibility = " + getJavaVersionConstant(settings.getSourceCompatibility()));
}

@KENNYSOFT KENNYSOFT changed the title Use Use 'Toolchains for JVM projects' of Gradle 6.7+ Feb 26, 2021
@spring-projects-issues spring-projects-issues added the status: waiting-for-triage An issue we've not yet triaged label Feb 26, 2021
@wilkinsona
Copy link
Contributor

Thanks for the suggestion, but I don't think we should do this. Using Gradle's Toolchain support may result in it attempting to download a JDK to meet the project's needs. That's something that may not always be desirable and in some organisations it wouldn't be permitted. I think it's better if we leave it as an opt-in.

Let's see what the rest of the team thinks.

@KENNYSOFT
Copy link
Contributor Author

Cool, I think it will also be great if the feature added as opt-in. Thanks for your reply.

@wilkinsona
Copy link
Contributor

To be clear, I meant an opt-in once the project has been generated. We certainly won't add it as an option when generating a project as we don't want to overwhelm users with too much choice. We'll either implement it for all Gradle projects or it'll be a change that you can make yourself once the project has been generated.

@KENNYSOFT
Copy link
Contributor Author

Ok I see.

@snicoll
Copy link
Contributor

snicoll commented Mar 1, 2021

As Andy mentioned, we really need to add what is strictly necessary out-of-the-box and let users complete their build with additional options if necessary. Thanks for the suggestion, in any case.

@tryfilter
Copy link

I come to this issue from a broken Java 21 project (Gradle 8.4):
Project: Gradle - Groovy
Language: Java
Spring Boot: 3.1.5
Java: 21
Running ./gradlew build on a project generated by this config fails with
"Execution failed for task ':compileJava'.

error: invalid source release: 21".

I don't follow the reasoning provided for declining this issue: from what I can tell, automatically downloading JDKs is opt-in from Gradle's POV. A toolchain download repository must be explicitly configured for any download to happen. I would argue that if such a repository is added to the config by the user, their intention is clear.
The Gradle docs do explicitly say that toolchains are generally preferred over sourceCompatibility and targetCompatibility and the above failure is one possible reason why.

My use case is admittedly somewhat niche as it should disappear when Gradle 8.5 is released, but I wanted to add another vote for toolchain support in favor of the current sourceCompatibility approach.

@snicoll
Copy link
Contributor

snicoll commented Nov 22, 2023

My use case is admittedly somewhat niche as it should disappear when Gradle 8.5 is released

That, and I am not sure you should get that issue in the first place. It looks like your shell is not using Java 21. What does ./gradlew --version output?

@tryfilter
Copy link

You are correct, my shell was using Java 17.
I assumed this was not the only problem since Gradle claims that 8.4 does not yet support running on Java 21 (and IntelliJ was reporting errors along the lines of "JDK 21.0.1 isn't compatible with Gradle 8.4").
But it seems like Gradle 8.4 runs on Java 21 just fine (making Gradle run on Java 21 fixed the error).
Thank you.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

5 participants