java - Maven 3.8.0 编译器 - 编译时出现 fatal error : release version 11 not supported

标签 java linux maven ubuntu java-11

我无法使用 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 的问题包裹:

➜  ~ 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 就成功了。

关于java - Maven 3.8.0 编译器 - 编译时出现 fatal error : release version 11 not supported,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/51631346/

相关文章:

java - Spring Security 每次都返回相同的 token

linux - 正在尝试更新 GPG。我的系统给出了相互矛盾的结果

java 忽略命令行参数中的代理

android - Maven 无法将 git-push 构建版本发布到存储库

maven - 如何防止 Maven 为我的存储库中已有的 Artifact 下载 maven-metadata.xml?

java - Android 登录页面无法正常工作

java - 在flex中分割字符串有问题吗?

java - 为单元测试序列化对象

php - 适用于 PHP 的 AWS 开发工具包无法在多个目录中运行

linux - 尝试设置断点时,gdb 无法访问附加进程中的内存