java.lang.IllegalArgumentException: error: release version 11 not supported

Hello,

I have setup a build agent with openjdk 11 on RHEL 9. In my application I am using toolchain for java 11 in root build.gradle.

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

Gradle version being used is 7.0 as gradle wrapper.

When building the application, I am getting the error “java.lang.IllegalArgumentException: error: release version 11 not supported”

Caused by: java.lang.IllegalArgumentException: error: release version 11 not supported
        at jdk.compiler/com.sun.tools.javac.main.Arguments.reportDiag(Arguments.java:891)
        at jdk.compiler/com.sun.tools.javac.main.Arguments.handleReleaseOptions(Arguments.java:311)
        at jdk.compiler/com.sun.tools.javac.main.Arguments.processArgs(Arguments.java:350)
        at jdk.compiler/com.sun.tools.javac.main.Arguments.init(Arguments.java:246)
        at jdk.compiler/com.sun.tools.javac.api.JavacTool.getTask(JavacTool.java:185)
        at jdk.compiler/com.sun.tools.javac.api.JavacTool.getTask(JavacTool.java:119)
        at jdk.compiler/com.sun.tools.javac.api.JavacTool.getTask(JavacTool.java:68)
        at org.gradle.api.internal.tasks.compile.JdkTools$DefaultIncrementalAwareCompiler.getTask(JdkTools.java:131)
        at org.gradle.api.internal.tasks.compile.JdkJavaCompiler.createCompileTask(JdkJavaCompiler.java:71)
        at org.gradle.api.internal.tasks.compile.JdkJavaCompiler.execute(JdkJavaCompiler.java:54)
        at org.gradle.api.internal.tasks.compile.JdkJavaCompiler.execute(JdkJavaCompiler.java:40)
        at org.gradle.api.internal.tasks.compile.NormalizingJavaCompiler.delegateAndHandleErrors(NormalizingJavaCompiler.java:97)

While on different platform it was suggested that only having jre is causing this issue and should have jdk (i.e javac) installed. As suggested I have installed java-11-openjdk-devel package as well and can see javac and java both pointing to same version but still getting error while running gradle build.

java --version
openjdk 11.0.24 2024-07-16 LTS
OpenJDK Runtime Environment (Red_Hat-11.0.24.0.8-2) (build 11.0.24+8-LTS)
OpenJDK 64-Bit Server VM (Red_Hat-11.0.24.0.8-2) (build 11.0.24+8-LTS, mixed mode, sharing)
javac -version
javac 11.0.24

PS: Earlier this application was getting built on a Ubuntu based Agent and I can see there’s no javac installed still build worked fine there.

Any suggestion how can I figure out root cause and fix it ?

Can you show the full error?
Optimally using a build --scan URL if possible.

And additionally, what does the javaToolchains task show?

Hi @Vampire I have rechecked it. I noticed that After installing the java-11-openjdk-devel, I forgot to stop the gradle daemon using ./gradlew -stop, that’s why it was not working on RHEL 9.

Before installing java-11-openjdk-devel

./gradlew -q javaToolchains

 + Options
     | Auto-detection:     Enabled
     | Auto-download:      Enabled

 + Red Hat, Inc. JRE 11.0.24
     | Location:           /usr/lib/jvm/java-11-openjdk-11.0.24.0.8-2.el9.x86_64
     | Language Version:   11
     | Vendor:             Red Hat, Inc.
     | Is JDK:             false

After Installing the package:

./gradlew -stop
Stopping Daemon(s)
1 Daemon stopped

./gradlew -q javaToolchains

 + Options
     | Auto-detection:     Enabled
     | Auto-download:      Enabled

 + Red Hat, Inc. JDK 11.0.24
     | Location:           /usr/lib/jvm/java-11-openjdk-11.0.24.0.8-2.el9.x86_64
     | Language Version:   11
     | Vendor:             Red Hat, Inc.
     | Is JDK:             true
     | Detected by:        Common Linux Locations

After this compileJava task of my subproject is working fine, no java release support error any more.

Now one thing which I am still not clear is that on an existing ubuntu (20.04) agent I only have JRE not jdk, but I am not getting any error (of missing javac) while running the compileJava task of same subproject.

./gradlew -q javaToolchains

 + Options
     | Auto-detection:     Enabled
     | Auto-download:      Enabled

 + Ubuntu JRE 11.0.24
     | Location:           /usr/lib/jvm/java-11-openjdk-amd64
     | Language Version:   11
     | Vendor:             Ubuntu
     | Is JDK:             false
     | Detected by:        Common Linux Locations

 + Ubuntu JRE 17.0.12
     | Location:           /usr/lib/jvm/java-17-openjdk-amd64
     | Language Version:   17
     | Vendor:             Ubuntu
     | Is JDK:             false
     | Detected by:        Common Linux Locations

is there any difference how gradle toolchain behave on different OS ? does gradle automatically pulls required compiler libraries on ubuntu but not on RHEL 9 ?

Thanks

You probably would need to debug what the exact difference is.
Gradle per-se should not behave different depending on OS.
But the packaging on those systems are probably simply different.
Iirc “Is JDK” is displayed as true if Java compiler and JavaDoc tool are found.
But not necessarily as binary executables, but from Java code.
So maybe on the Ubuntu system the Java compiler is present but the JavaDoc is missing or something like that.
:man_shrugging: