docker-gradle icon indicating copy to clipboard operation
docker-gradle copied to clipboard

Gradle, Docker and JDK 22 issue

Open sergey-morenets opened this issue 8 months ago • 6 comments

Hi

I failed to build my application using Gradle 8.8 and JDK 22. I assume from the documentation that current Docker image supports both JDK 21 and 22 using specific gradle.properties:

org.gradle.java.installations.auto-detect=false
org.gradle.java.installations.auto-download=false
org.gradle.java.installations.fromEnv=JAVA_LTS_HOME,JAVA_CURRENT_HOME

Unfortunately if I try to build my application using this default configuration I receive an error:

error: invalid source release: 22

So I changed this gradle.properties to using only current (JDK22) JDK version:

org.gradle.java.installations.auto-detect=false
org.gradle.java.installations.auto-download=false
org.gradle.java.installations.fromEnv=JAVA_CURRENT_HOME

But the error still happens and I see from the logs that Gradle build still uses JDK 21:

Received JVM installation metadata from '/opt/java/openjdk': {JAVA_HOME=/opt/java/openjdk, JAVA_VERSION=21.0.3, JAVA_VENDOR=Eclipse Adoptium, RUNTIME_NAME=OpenJDK Runtime Environment, RUNTIME_VERSION=21.0.3+9-LTS, VM_NAME=OpenJDK 64-Bit Server VM, VM_VERSION=21.0.3+9-LTS, VM_VENDOR=Eclipse Adoptium, OS_ARCH=amd64}

Here is my Dockerfile:

FROM gradle:8-jdk-21-and-22-alpine 

COPY gradle.properties /home/gradle/.gradle/gradle.properties

COPY . /home/gradle/

RUN  gradle --info clean build 

and build.gradle.kts:

plugins {
    id("java-library") 
}

   java { 
       sourceCompatibility = org.gradle.api.JavaVersion.VERSION_22
       targetCompatibility = org.gradle.api.JavaVersion.VERSION_22
   }   

Please, advise how to build Docker image for Java 22 application.

sergey-morenets avatar Jun 15 '24 10:06 sergey-morenets