我无法使用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.
答案 0 :(得分:9)
mvn需要设置In [18]: torch.set_printoptions(edgeitems=1)
In [19]: a
Out[19]:
tensor([[-0.7698, ..., -0.1949],
...,
[-0.7321, ..., 0.8537]])
In [20]: torch.set_printoptions(edgeitems=3)
In [21]: a
Out[21]:
tensor([[-0.7698, 1.3383, 0.5649, ..., 1.3567, 0.6896, -0.1949],
[-0.5761, -0.9789, -0.2058, ..., -0.5843, 2.6311, -0.0008],
[ 1.3152, 1.8851, -0.9761, ..., 0.8639, -0.6237, 0.5646],
...,
[ 0.2851, 0.5504, -0.9471, ..., 0.0688, -0.7777, 0.1661],
[ 2.9616, -0.8685, -1.5467, ..., -1.4646, 1.1098, -1.0873],
[-0.7321, 0.7610, 0.3182, ..., 2.5859, -0.9709, 0.8537]])
。我遇到了同样的问题,并设置了JAVA_HOME
来纠正JDK的问题。
答案 1 :(得分:2)
我看到您正在使用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:29 + 02:00) Maven主页:C:\ 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”,版本:“ 10.0”,拱门:“ amd64”,家族:“ windows”
然后重试mvn全新安装
如果不走运,请共享您的pom.xml,以便我们查看可能使您的构建失败的配置。
答案 2 :(得分:1)
对我来说,这是因为安装了Java 11 JRE而不是JDK。文件夹名称中包含“ jdk”,因此我认为它是正确的,但是在/bin
文件夹中,我没有看到javac
可执行文件,因此我认为它已恢复为默认名称早于Java 11的系统上的Java。
答案 3 :(得分:1)
在使用Docker映像adoptopenjdk/openjdk13:alpine-slim
:The JDK "slim" image does not support the "--release" flag in the javac command
答案 4 :(得分:0)
在终端中:
mvn -version
示例-Java版本:9.0.p
更多使用的插件:
<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>
答案 5 :(得分:0)
在Docker容器中构建Java项目时遇到此错误。它一定与maven的安装方式有关,因为当我将容器基于official maven image时,它消失了。
特别是,这意味着在我的Dockerfile中使用以下内容:
FROM maven:3.6.3-jdk-11-slim
在进一步调查中,关键的区别是我拥有软件包java-11-openjdk
,但我需要java-11-openjdk-devel
。
答案 6 :(得分:0)
我在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
更多详细信息在这里。我发现这很有用。
答案 7 :(得分:0)
对我来说是一个类似的错误,特别是 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>
它正在工作。当我在 verbose mode 中运行 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
)产生了否定断言。
答案 8 :(得分:0)
正如消息指定的那样,这是一个版本问题,我引导了一个 spring 项目,当我的电脑上实际上有 java 8 时,我选择了 java 11。我只是去巴赫用适当的 Java 版本重新创建我的项目,错误消失了