java - 由于源 1.5,无法构建包目标
问题描述
当我清理项目并以干净的方式运行时,一切正常。然后,当我尝试以 build.. 运行并将目标设置为 package 时,我收到此错误:
[ERROR] Failed to execute goal org.apache.maven.plugins:maven-compiler-plugin:3.1:compile (default-compile) on project smart.mirror: Compilation failure: Compilation failure:
[ERROR] /C:/Users/user/Desktop/smart.mirror/src/main/java/iezon/smart/mirror/views/ApplicationView.java:[29,65] multi-catch statement is not supported in -source 1.5
[ERROR] (use -source 7 or higher to enable multi-catch statement)
[ERROR] /C:/Users/user/Desktop/smart.mirror/src/main/java/iezon/smart/mirror/App.java:[119,49] multi-catch statement is not supported in -source 1.5
[ERROR] (use -source 7 or higher to enable multi-catch statement)
[ERROR] /C:/Users/user/Desktop/smart.mirror/src/main/java/iezon/smart/mirror/views/Login.java:[86,51] lambda expressions are not supported in -source 1.5
[ERROR] (use -source 8 or higher to enable lambda expressions)
[ERROR] /C:/Users/user/Desktop/smart.mirror/src/main/java/iezon/smart/mirror/views/Login.java:[136,49] multi-catch statement is not supported in -source 1.5
[ERROR] (use -source 7 or higher to enable multi-catch statement)
[ERROR] /C:/Users/user/Desktop/smart.mirror/src/main/java/iezon/smart/mirror/views/Application.java:[88,65] multi-catch statement is not supported in -source 1.5
[ERROR] (use -source 7 or higher to enable multi-catch statement)
[ERROR] /C:/Users/user/Desktop/smart.mirror/src/main/java/iezon/smart/mirror/views/Application.java:[158,103] lambda expressions are not supported in -source 1.5
[ERROR] (use -source 8 or higher to enable lambda expressions)
[ERROR] /C:/Users/user/Desktop/smart.mirror/src/main/java/iezon/smart/mirror/Application.java:[120,48] multi-catch statement is not supported in -source 1.5
[ERROR] (use -source 7 or higher to enable multi-catch statement)
大多数行上的 multicatch 看起来像这样,但是当我运行应用程序时,应用程序工作正常。
catch (InstantiationException | IllegalAccessException e)
我不确定采购 1.5 是什么意思,我用谷歌搜索了如何在包构建时更改 Maven 源,但找不到任何东西。任何帮助表示赞赏。
解决方案
尝试直接配置 maven-compiler-plugin,如果你还没有在你的 (super)pom.xml 中明确包含它。添加以下内容:
<build>
[...]
<plugins>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-compiler-plugin</artifactId>
<version>3.8.0</version>
<configuration>
<source>1.8</source>
<target>1.8</target>
</configuration>
</plugin>
</plugins>
[...]
</build>
推荐阅读
- java - 如何在 Java 中实现可通过列名和行号访问的可变大小表?
- javascript - 尝试使用数组中的信息进行绘制
- docusignapi - DocuSign API 可以读取历史状态吗?
- css - 有没有办法在 Draw2D 驱动的画布上拥有 iframe 元素?
- python - 如何使用python证明两条线段在autocad中是否相交
- javascript - 我可以用新的 chrome 运行 cypress 吗?
- excel-formula - 确定一个范围内唯一递增值的数量
- javascript - 通过 javascript 从 MySQL 数据库中读取数据并相应地更改收音机的 prop
- c# - 如何使用 C# 驱动程序从现有的索引定义创建 Mongo 索引定义?
- nativescript - 没有得到http请求响应