Release version 11 not supported while using Gradle on MacOS with AdoptOpenJDK 11

3.6k Views Asked by At

When running gradle build (that works for other developers in my team) I'm getting:

Execution failed for task ':compileJava'.
> error: release version 11 not supported

This is with installation of AdoptOpenJDK11 on MacOS.

java -version
openjdk version "11.0.11" 2021-04-20
OpenJDK Runtime Environment AdoptOpenJDK-11.0.11+9 (build 11.0.11+9)
OpenJDK 64-Bit Server VM AdoptOpenJDK-11.0.11+9 (build 11.0.11+9, mixed mode)
 ./gradlew -version                    

------------------------------------------------------------
Gradle 6.8.2
------------------------------------------------------------

Build time:   2021-02-05 12:53:00 UTC
Revision:     b9bd4a5c6026ac52f690eaf2829ee26563cad426

Kotlin:       1.4.20
Groovy:       2.5.12
Ant:          Apache Ant(TM) version 1.10.9 compiled on September 27 2020
JVM:          11.0.11 (AdoptOpenJDK 11.0.11+9)
OS:           Mac OS X 10.14.6 x86_64

echo $JAVA_HOME
/Library/Java/JavaVirtualMachines/adoptopenjdk-11.jdk/Contents/Home

Relevant part of build.grade

...
java {
    toolchain {
        languageVersion.set(JavaLanguageVersion.of(11))
    }
}
...
gradle -q javaToolchains
executing gradlew instead of gradle

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

 + AdoptOpenJDK 11.0.11
     | Location:           /Library/Java/JavaVirtualMachines/adoptopenjdk-11.jdk/Contents/Home
     | Language Version:   11
     | Vendor:             AdoptOpenJDK
     | Is JDK:             true
     | Detected by:        Current JVM

It seems that java toolchain feature of gradle is causing issues.

  • If the java toolchains block is completely removed, project builds fine using current JVM.
  • If java toolchains is set to use java 12, gradle will download jdk12 and again it builds fine.
  • Running javac from existing JDK11 via command line to compile a dummy hello world file also works fine (e.g. /Library/Java/JavaVirtualMachines/adoptopenjdk-11.jdk/Contents/Home/bin/javac --release 11 HelloWorld.java)

I suspect reinstalling JDK would solve this but I would really appreciate any clues on how to debug this further and understand why it is happening.

UPDATE

After attempting several debugging steps, build now works, for reasons unknown to me. Unfortunately I do not know why it didn't work initially and can't reproduce the issues again to debug further. For future reference to people who may encounter this issue, here are some of the steps I did in the debugging process. One of these apparently fixed the issue, though I don't know how:

  • Removed java toolchains section and trying build that way, then adding back the java toolchains section
  • Trying the build setting java toolchains to use java 12 (this resulted in automatic provisioning of jdk12 by gradle)
  • Running gradle -q javaToolchains
  • Removing jdk12 (that was automatically provisioned by gradle) from ~/.gradle/jdks
1

There are 1 best solutions below

0
On

On a (Linux) machine with no Java on it at all, I installed Java 11 and got the same errors.

The interesting part of my stacktrace was this:

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)

and this part of the verbose output:

2021-07-30T10:29:27.874+0000 [INFO] [org.gradle.jvm.toolchain.internal.DefaultToolchainJavaCompiler] Compiling with toolchain '/usr/lib/jvm/java-11-openjdk-11.0.12.0.7-0.el8_4.x86_64'.
2021-07-30T10:29:27.882+0000 [DEBUG] [org.gradle.api.internal.tasks.compile.NormalizingJavaCompiler] Compiler arguments: --release 11 -d /home/tim/git/bma_emubroker/bma-emubroker/build/classes/java/main -h /home/tim/git/bma_emubroker/bma-emubroker/build/generated/sources/headers/java/main -g -sourcepath  -proc:none -s /home/tim/git/bma_emubroker/bma-emubroker/build/generated/sources/annotationProcessor/java/main...huge.line.tuncated

In trying to reconstruct and run the toolchain command, filename completion pointed out to me that javac wasn't available!

Running 'sudo yum install java-devel-11' to install the SDK in addition to the JDK, and running './gradlew --stop' to kill the daemons fixed it for me.