Maven "error: release version 17 not supported" - Fix JDK in CI
javac rejected the requested --release because the JDK compiling your code is older than that language level. A JDK 11 cannot emit release 17 - it has no knowledge of that version.
What this error means
Compilation aborts with error: release version 17 not supported. The number is the maven.compiler.release your POM requests; the JDK actually running is older than it.
[ERROR] Failed to execute goal
org.apache.maven.plugins:maven-compiler-plugin:3.13.0:compile (default-compile)
on project app: Compilation failure
[ERROR] error: release version 17 not supportedCommon causes
Runner JDK older than maven.compiler.release
CI defaulted to an older JDK (e.g. 11) while the POM sets <maven.compiler.release>17</maven.compiler.release>. The compiler does not support a release newer than itself.
JAVA_HOME resolves to the wrong JDK
Multiple JDKs are installed and JAVA_HOME (or PATH) points at the older one, so Maven compiles with it regardless of intent.
How to fix it
Provision the matching JDK
Set up the JDK your release targets and verify Maven uses it.
- uses: actions/setup-java@v4
with:
distribution: temurin
java-version: '17'
- run: mvn -B -versionLower the release to fit the JDK
If you cannot upgrade, set the release no higher than the running JDK.
<properties>
<maven.compiler.release>11</maven.compiler.release>
</properties>How to prevent it
- Pin the JDK with setup-java, assert it with
mvn -version, and keepmaven.compiler.releaseno higher than the provisioned JDK.