![](/img/trans.png)
[英]maven-comiler-plugin: Fatal error compiling: error: release version 17 not supported
[英]Maven 3.8.0 Compiler - Fatal error compiling: release version 11 not supported
我無法使用 Java 11 和最新版本的 maven-compiler-plugin 進行構建。
pom.xml:
<build>
<plugins>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-compiler-plugin</artifactId>
<version>3.8.0</version>
<configuration>
<release>11</release>
</configuration>
</plugin>
<plugins>
<build>
當我嘗試使用 Maven 進行構建時:
➜ mvn clean compile
[INFO] Scanning for projects...
[INFO]
[INFO] ------------------------------------------------------------------------
[INFO] Building service 0.0.1-SNAPSHOT
[INFO] ------------------------------------------------------------------------
[INFO]
[INFO] --- maven-compiler-plugin:3.8.0:compile (default-compile) @ service ---
[INFO] Changes detected - recompiling the module!
[INFO] Compiling 80 source files to /home/mip/service/target/classes
[INFO] ------------------------------------------------------------------------
[INFO] BUILD FAILURE
[INFO] ------------------------------------------------------------------------
[INFO] Total time: 2.859 s
[INFO] Finished at: 2018-08-01T11:20:55+01:00
[INFO] Final Memory: 32M/124M
[INFO] ------------------------------------------------------------------------
[ERROR] Failed to execute goal org.apache.maven.plugins:maven-compiler-plugin:3.8.0:compile (default-compile) on project service: Fatal error compiling: release version 11 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
這是我正在使用的 Maven 和 Java 版本:
➜ mvn -version
Apache Maven 3.5.2
Maven home: /usr/share/maven
Java version: 10.0.1, vendor: Oracle Corporation
Java home: /usr/lib/jvm/java-11-openjdk-amd64
Default locale: en_GB, platform encoding: UTF-8
OS name: "linux", version: "4.15.0-29-generic", arch: "amd64", family: "unix"
➜ /usr/lib/jvm/java-11-openjdk-amd64/bin/java -version
openjdk version "10.0.1" 2018-04-17
OpenJDK Runtime Environment (build 10.0.1+10-Ubuntu-3ubuntu1)
OpenJDK 64-Bit Server VM (build 10.0.1+10-Ubuntu-3ubuntu1, mixed mode)
Java 11 將自己標識為“10.0.1”會導致問題嗎? 如果我將我的 pom.xml 修改為<release>10</release>
然后它構建沒有問題,即使我沒有安裝 Java 10。
➜ ~ /usr/lib/jvm/java-11-openjdk-amd64/bin/javac -version
javac 10.0.1
➜ javac --release 11 SomeClass.java
javac: release version 11 not
supported Usage: javac <options> <source files>
use --help for a list of possible options
我認為這是 Ubuntu openjdk-11-jdk
package 的問題:
➜ ~ sudo apt install openjdk-11-jdk
Reading package lists... Done
Building dependency tree
Reading state information... Done
openjdk-11-jdk is already the newest version (10.0.1+10-3ubuntu1).
0 to upgrade, 0 to newly install, 0 to remove and 2 not to upgrade.
mvn 需要JAVA_HOME
。 我遇到了同樣的問題,設置JAVA_HOME
來糾正 JDK 就成功了。
我在 docker 容器中構建 java 項目時遇到了這個錯誤。 它一定與 maven 的安裝方式有關,因為當我將容器基於官方 maven image時它就消失了。
特別是,這意味着在我的 Dockerfile 中使用以下內容:
FROM maven:3.6.3-jdk-11-slim
經過進一步調查,關鍵的區別在於我有java-11-openjdk
包,但我需要java-11-openjdk-devel
。
對我來說,這是因為安裝了 Java 11 JRE 而不是 JDK。 文件夾名稱中有“jdk”,所以我認為它是正確的,但是在/bin
文件夾中我沒有看到javac
可執行文件,所以我認為它正在回退到系統上的默認 Java 較早比 Java 11。
我看到您正在使用 Java 9,要使用 Java 11 構建,請嘗試以下操作:
確保 JAVA_HOME 設置為 C:\\Program Files\\Java\\jdk-11......
在您的 pom.xml 中添加"<properties> <java.version>11</java.version> </properties>"
並在適用的地方引用 ${java.version}。
“mvn -v”應該輸出這樣的東西(取決於你的 maven 和 java 安裝在你機器上的位置):Apache Maven 3.6.1 (d66c9c0b3152b2e69ee9bac180bb8fcc8e6af555; 2019-04-04T21:00:209)02 :\\Program Files (x86)\\Apache-Maven-3.6.1\\bin.. Java 版本:11.0.6,供應商:Oracle Corporation,運行時:C:\\Program Files\\Java\\jdk-11.0.6 默認語言環境:en_US , 平台編碼: Cp1252 操作系統名稱: "windows 10", version: "10.0", arch: "amd64", family: "windows"
然后重試 mvn clean install
如果不走運,請分享您的 pom.xml,以便我們可以看到可能會導致構建失敗的配置。
在終端:
mvn -version
示例 - Java 版本:9.0.4
進一步使用的插件:
<plugins>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-compiler-plugin</artifactId>
<version>3.8.1</version>
<configuration>
<release>9.0.4</release>
</configuration>
</plugin>
</plugins>
我在 centOS 7 中遇到了類似的問題。
Fatal error compiling: error: release version 11 not supported
我有 jre 但缺少 jdk。 您可以通過運行javac
命令來解決這個問題。 說找不到命令,然后需要安裝jdk。
安裝 Java 11 JDK
sudo yum install java-11-openjdk-devel
安裝 Java 11 JRE
sudo yum install java-11-openjdk
更多細節在這里。 我發現這很有用。
對我來說一個類似的錯誤,特別是java.lang.AssertionError
[ERROR] Failed to execute goal org.apache.maven.plugins:maven-compiler-plugin:3.8.1:compile (default-compile) on project nospringboot: Fatal error compiling: java.lang.AssertionError: Version '14' not supported -> [Help 1]
由於依賴項之一而發生。 我換了
<groupId>org.testifyproject.mock</groupId>
<artifactId>mockito</artifactId>
<version>1.0.6</version>
和
<groupId>org.mockito</groupId>
<artifactId>mockito-all</artifactId>
<version>1.9.5</version>
它正在工作。 當我以詳細模式運行 maven build 並打印此輸出時,我意識到了這一點:
Caused by: java.lang.AssertionError: Version '14' not supported
at org.testifyproject.processor.DiscoverableProcessor.getSupportedSourceVersion(DiscoverableProcessor.java:67)
at jdk.compiler/com.sun.tools.javac.processing.JavacProcessingEnvironment$ProcessorState.checkSourceVersionCompatibility(JavacProcessingEnvironment.java:764)
at jdk.compiler/com.sun.tools.javac.processing.JavacProcessingEnvironment$ProcessorState.<init>(JavacProcessingEnvironment.java:704)
at jdk.compiler/com.sun.tools.javac.processing.JavacProcessingEnvironment$DiscoveredProcessors$ProcessorStateIterator.next(JavacProcessingEnvironment.java:830)
at jdk.compiler/com.sun.tools.javac.processing.JavacProcessingEnvironment.discoverAndRunProcs(JavacProcessingEnvironment.java:926)
at jdk.compiler/com.sun.tools.javac.processing.JavacProcessingEnvironment$Round.run(JavacProcessingEnvironment.java:1270)
...
它顯示了哪個方法(在哪個特定包中: org.testifyproject.processor.DiscoverableProcessor.getSupportedSourceVersion(DiscoverableProcessor.java:67
) 產生了否定斷言。
正如消息指定的那樣,這是一個版本問題,我引導了一個 spring 項目,當我的電腦上實際上有 java 8 時,我選擇了 java 11。 我只是去 bach 用適當的 Java 版本重新創建我的項目,錯誤就消失了
如果您在 Eclipse 中遇到此錯誤,請嘗試在下載並設置最新的 Maven 版本(包括將MAVEN_HOME
環境變量設置為您的安裝路徑)后在 Eclipse 之外編譯您的項目。
如果您的項目在 Eclipse 外部編譯但沒有在內部編譯,則檢查您的 Maven 配置使用的 jdk:
Maven Build
配置JRE
選項卡並確保使用了正確的 JRE。
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.