java - 将 1.8 Maven 项目更改为编译为 1.16 会产生“无效的目标版本 1.16”
问题描述
我一直在寻找解决方案几个小时,甚至找不到一篇关于 maven 编译到 1.16 的帖子
我最近决定将我的一个项目从 java 8 升级到 16,因此我安装了 16 个 JDK 并相应地更改了我的构建部分(在 pom.xml 中):
<build>
<plugins>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-compiler-plugin</artifactId>
<version>3.8.1</version>
<configuration>
<source>1.16</source> //used to be 1.8
<target>1.16</target> //used to be 1.8
<compilerArgs>
<arg>-parameters</arg>
</compilerArgs>
</configuration>
</plugin>
</plugins>
</build>
但是当我尝试安装时出现以下错误:
[INFO] Total time: 0.628 s
[INFO] Finished at: 2021-08-03T22:40:27+03:00
[INFO] ------------------------------------------------------------------------
[ERROR] Failed to execute goal org.apache.maven.plugins:maven-compiler-plugin:3.8.1:compile (default-compile) on project employeme: Fatal error compiling: error: invalid target release: 1.16 -> [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
解决方案
- It's not
1.16
, it's16
. - You don't have to configure the
maven-compiler-plugin
. - You can use the new
release
option.
<properties>
<maven.compiler.release>16</maven.compiler.release>
</properties>
推荐阅读
- javascript - 有没有办法从 JavaScript 的 setTimeout 循环中退出 if 语句?
- python - 尝试下载 MNIST 数据时出现 HTTP 错误
- python - 将句子中的 N 位数字替换为 N 的不同值的特定字符串
- python - 为什么函数不检查到最后一个数字?
- javascript - 对带有异常的 javascript 对象进行排序
- python - 在数值对数 X 轴上绘制垂直箱线图
- .net-core - 相同的功能有时会让我退出 (ReturnUrl)
- sql - 仅显示结果 > 2
- c - 如何使用两个指针来定义一个字符串isPalindrome?
- reactjs - 如何根据当前 url 激活 antd 侧边栏菜单项?