首页 > 解决方案 > 由于源 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 源,但找不到任何东西。任何帮助表示赞赏。

标签: javamaven

解决方案


尝试直接配置 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>

推荐阅读