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

Create a Java 17 image that also contains Java 20 #248

Closed
wants to merge 2 commits into from

Conversation

keeganwitt
Copy link
Owner

The latest (8.1.1) release notes say

Gradle now supports using Java 20 for compiling, testing, and starting other Java programs. This can be accomplished by configuring your build or task to use a Java 20 toolchain.

You cannot currently run Gradle on Java 20 because Kotlin lacks support for JDK 20. However, you can expect support for running Gradle with Java 20 in a future version.

They also note this in their compatibility guide.

My hope was that full Java 20 support was coming soon, but it sounds like it might not be until 8.2 (July). See the issue gradle/gradle#23488.

This PR adds an image based on the Java 17 image but also installs Java 20 so that you can use it in a toolchain.

@keeganwitt
Copy link
Owner Author

keeganwitt commented May 8, 2023

This can be used with

Groovy DSL

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

kotlin {
    jvmToolchain {
        languageVersion = JavaLanguageVersion.of(20)
    }
}

or
Kotlin DSL

java {
    toolchain {
        languageVersion.set(JavaLanguageVersion.of(20))
    }
}

kotlin {
    jvmToolchain {
        languageVersion.set(JavaLanguageVersion.of(20))
    }
}

And invoke gradle with these args

-Porg.gradle.java.installations.auto-detect=false
-Porg.gradle.java.installations.auto-download=false
-Porg.gradle.java.installations.fromEnv=JAVA20_HOME
# you could use the below line instead of the above line
-Porg.gradle.java.installations.paths=/opt/java/openjdk20

@MartelliEnrico
Copy link

These properties could be set inside .gradle/gradle.properties, so that they are automatically read and used by the gradle command

@keeganwitt
Copy link
Owner Author

These properties could be set inside .gradle/gradle.properties, so that they are automatically read and used by the gradle command

That's true, but I thought that would be inconvenient for running your project locally.

@MartelliEnrico
Copy link

What I meant was to set these properties inside the docker image, so that only when running gradle from the image the toolchain whould be manually set. I don't think it will impact using gradle locally

@keeganwitt
Copy link
Owner Author

What I meant was to set these properties inside the docker image, so that only when running gradle from the image the toolchain whould be manually set. I don't think it will impact using gradle locally

Oh, with GRADLE_OPTS?

@MartelliEnrico
Copy link

I was actually thinking about creating a file inside the docker image, but an ENV is also a good option

@keeganwitt
Copy link
Owner Author

Does anyone have a need for this image? Should we go forward with creating it?

@jurriaan
Copy link
Contributor

We're currently stuck on an old jdk19/gradle8.0 build of docker-gradle. We're using jdk19 and want to upgrade to jdk20 and Gradle 8.2, but can't due a build with jdk20 is missing.

@keeganwitt
Copy link
Owner Author

@MartelliEnrico I see which file you mean now (I originally thought you meant the project's .gradle directory). That is a good suggestion. since that will make it less likely to be accidentally wiped out by people setting their own GRADLE_OPTS.

@keeganwitt
Copy link
Owner Author

@jurriaan I held off on making another image I'd have to maintain because I wasn't sure anyone needed this. Now that you said you do, I'll proceed with merging it.

@jurriaan
Copy link
Contributor

@keeganwitt JDK20 is supported with Kotlin 1.9.0, right? Am I correct that this JDK 17 + 20 approach isn't needed anymore when gradle/gradle#25777 is merged? Maybe we can wait for that instead of releasing this combined image?

@keeganwitt
Copy link
Owner Author

@keeganwitt JDK20 is supported with Kotlin 1.9.0, right? Am I correct that this JDK 17 + 20 approach isn't needed anymore when gradle/gradle#25777 is merged? Maybe we can wait for that instead of releasing this combined image?

That's right, but there hasn't been a version of Gradle released that is on Kotlin 1.9.0. The last I saw in the linked issue, it will be shipped in Gradle 8.3.

I'd rather wait, since then we won't have the confusion of when this new image is EOL, but it's really up to whatever people need.

@keeganwitt
Copy link
Owner Author

8.3 just got released this morning!

https://docs.gradle.org/8.3/release-notes.html#full-support-for-java-20

@keeganwitt keeganwitt closed this Aug 17, 2023
@keeganwitt keeganwitt deleted the gradle_8.1_java20 branch April 5, 2024 18:59
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

3 participants