keeganwitt / docker-gradle

Docker images with Gradle
https://hub.docker.com/_/gradle/
Apache License 2.0
143 stars 73 forks source link

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

Closed keeganwitt closed 1 year ago

keeganwitt commented 1 year ago

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 https://github.com/gradle/gradle/issues/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 commented 1 year ago

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 commented 1 year ago

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

keeganwitt commented 1 year ago

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 commented 1 year ago

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 commented 1 year ago

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 commented 1 year ago

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

keeganwitt commented 1 year ago

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

jurriaan commented 1 year ago

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 commented 1 year ago

@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 commented 1 year ago

@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 commented 1 year ago

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

keeganwitt commented 1 year ago

@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 commented 1 year ago

8.3 just got released this morning!

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