できない.dev

Maven「release version 25 not supported」の原因と直し方

release version 25 not supported は、JDK を 25 以上にするか release を下げれば直る。
Maven を動かしている JDK が、pom.xml に書いた Java のバージョンより古いと出る。

公開: 更新:

症状できない · exit 1
mvn compile
…
[ERROR] Failed to execute goal org.apache.maven.plugins:maven-compiler-plugin:3.16.0:compile (default-compile) on project demo: Fatal error compiling: error: release version 25 not supported -> [Help 1]
[ERROR]
[ERROR] To see the full stack trace of the errors, re-run Maven with the -e switch.
[ERROR] Re-run Maven using the -X switch to enable full debug logging.

2026-10-31 に maven:3-eclipse-temurin-21(Git 2.53.0) で実際に打って取った出力。検証環境の詳細

要約

mvn compile がコンパイルの段階で止まる。
Maven 3.10.0・maven-compiler-plugin 3.16.0・JDK 21 の組み合わせで、pom.xml に Java 25 を指定すると次のように出る。

[INFO] Compiling 1 source file with javac [debug release 25] to target/classes
[ERROR] Failed to execute goal org.apache.maven.plugins:maven-compiler-plugin:3.16.0:compile (default-compile) on project demo: Fatal error compiling: error: release version 25 not supported -> [Help 1]

release version 25 not supported は、javac が --release 25 を受け付けなかったというエラーだ。
pom.xml の maven.compiler.release は javac の --release に渡される。
そして --release に指定できるのは、使っている JDK 自身のバージョンと、それより前の限られたバージョンだけである(Setting the --release of the Java Compiler(新しいタブで開く))。
JDK 21 の javac は、Java 25 向けのコンパイルができない。
数字は pom.xml に書いた値がそのまま出るので、17 や 21 でも原因は同じだ。

実行例

maven:3-eclipse-temurin-21 のコンテナで maven.compiler.release に 25 を書いて mvn compile を実行すると、release version 25 not supported で終了コード 1 になる。
mvn -v は、Maven が JDK 21.0.13 で動いていることを示している。

$ mvn compile
[INFO] Scanning for projects...
[INFO] 
[INFO] --------------------------< com.example:demo >--------------------------
[INFO] Building demo 1.0
[INFO]   from pom.xml
[INFO] --------------------------------[ jar ]---------------------------------
[INFO] Loaded 24316 auto-discovered prefixes for remote repository central (prefixes-central.txt)
[INFO] 
[INFO] --- resources:3.5.0:resources (default-resources) @ demo ---
[INFO] skip non existing resourceDirectory /tmp/tmp.8XEvZVOiKq/src/main/resources
[INFO] 
[INFO] --- compiler:3.16.0:compile (default-compile) @ demo ---
[INFO] Loaded 74 auto-discovered prefixes for remote repository apache.snapshots (prefixes-apache.snapshots.txt)
[INFO] Recompiling the module because of changed source code.
[INFO] Compiling 1 source file with javac [debug release 25] to target/classes
[INFO] ------------------------------------------------------------------------
[ERROR] BUILD FAILURE
[INFO] ------------------------------------------------------------------------
[INFO] Total time:  4.253 s
[INFO] Finished at: 2026-10-31T23:35:15Z
[INFO] ------------------------------------------------------------------------
[ERROR] Failed to execute goal org.apache.maven.plugins:maven-compiler-plugin:3.16.0:compile (default-compile) on project demo: Fatal error compiling: error: release version 25 not supported -> [Help 1]
[ERROR] 
[ERROR] To see the full stack trace of the errors, re-run Maven with the -e switch.
[ERROR] Re-run Maven using the -X switch to enable full debug logging.
[ERROR] 
[ERROR] For more information about the errors and possible solutions, please read the following articles:
[ERROR] [Help 1] http://cwiki.apache.org/confluence/display/MAVEN/MojoExecutionException
$ echo $?
1
$ mvn -v
Apache Maven 3.10.0 (c43a36b8d67be7e0805a411bc0898af1a51f5472)
Maven home: /usr/share/maven
Java version: 21.0.13, vendor: Eclipse Adoptium, runtime: /opt/java/openjdk
Default locale: en_US, platform encoding: UTF-8, time zone: Etc/UTC
OS name: "linux", version: "6.6.87.2-microsoft-standard-wsl2", arch: "amd64", family: "unix"
$ grep -n compiler pom.xml
7:    <maven.compiler.source>25</maven.compiler.source><maven.compiler.target>25</maven.compiler.target>

— 2026-10-31 時点の出力

検証環境Git 2.53.0 / 2026-10-31 検証
検証日
実行環境
maven:3-eclipse-temurin-21 Ubuntu 26.04.1 LTS
バージョン
  • Git 2.53.0

この記事の「実行例」は、上記の環境で実際にコマンドを実行して得られた出力をそのまま掲載しています。 再現手順はリポジトリの検証スクリプトとして管理し、定期的に再実行して出力を更新しています。

解決策

1. Maven が使っている JDK を確かめる

mvn -v
Apache Maven 3.10.0 (c43a36b8d67be7e0805a411bc0898af1a51f5472)
Maven home: /usr/share/maven
Java version: 21.0.12.1, vendor: Eclipse Adoptium, runtime: /opt/java/openjdk

Java version が Maven の使う JDK だ。
release の値より古ければ、2 か 3 で直す。

2. 新しい JDK で Maven を動かす

JDK 25 以上を入れ、JAVA_HOME をそこへ向ける。
切り替わったかは mvn -v で見る。

export JAVA_HOME=/path/to/jdk-25
mvn -v
mvn compile

GitHub Actions では、setup-java の java-version を pom.xml に合わせる。

- uses: actions/setup-java@v6
  with:
    distribution: temurin
    java-version: '25'

3. release を手元の JDK に合わせて下げる

Java 25 の言語機能や API を使っていないなら、release を手元の JDK 以下にする。

<properties>
  <maven.compiler.release>21</maven.compiler.release>
</properties>

古い source / target と違い、--release は指定したバージョンに無い標準 API の使用もコンパイル時に弾く。

4. Maven と別の JDK でコンパイルする

Maven は今の JDK で動かしたまま、コンパイルだけ別の JDK で行うなら Toolchains を使う(Guide to Using Toolchains(新しいタブで開く))。

よくある原因

  1. JDK が古い。
    pom.xml には 25 と書いたのに、Maven を動かしている JDK が 21 のままになっている。
    特に設定しなければ、Maven は自分を動かしている JDK の javac でコンパイルする。
  2. JAVA_HOME が古い JDK を指している。
    mvn の起動スクリプトは、JAVA_HOME が設定されていればその JDK の java で Maven を動かす。
    新しい JDK を入れて java -version が新しくなっても、JAVA_HOME が古いままなら Maven は古い JDK で動く。
  3. CI の JDK が古い。
    CI だけ落ちるなら、actions/setup-java の java-version などが pom.xml の指定より古い。
  4. source / target で書いている。
    maven.compiler.release ではなく maven.compiler.source と maven.compiler.target に 25 を書いた場合、同じ食い違いは error: invalid target release: 25 として出る。