Maven构建编译错误:无法执行目标org.apache.maven.plugins:maven-compiler-plugin:3.1:在项目Maven上编译(default-compile)

我有一个maven项目分叉并从git repo克隆到我的eclipse上。 它建立在Java 8之上。我做的第一件事就是执行一个

mvn clean install 

但我收到以下失败消息:

 [INFO] Scanning for projects... [INFO] [INFO] ------------------------------------------------------------------------ [INFO] Building Maven 0.0.1-SNAPSHOT [INFO] ------------------------------------------------------------------------ [INFO] [INFO] --- maven-clean-plugin:2.5:clean (default-clean) @ Maven --- [INFO] Deleting /Users/vshukla/git/Prism/target [INFO] [INFO] --- maven-resources-plugin:2.6:resources (default-resources) @ Maven --- [WARNING] Using platform encoding (UTF-8 actually) to copy filtered resources, ie build is platform dependent! [INFO] skip non existing resourceDirectory /Users/vshukla/git/Prism/src/main/resources [INFO] [INFO] --- maven-compiler-plugin:3.1:compile (default-compile) @ Maven --- [INFO] Changes detected - recompiling the module! [WARNING] File encoding has not been set, using platform encoding UTF-8, ie build is platform dependent! [INFO] Compiling 66 source files to /Users/vshukla/git/Prism/target/classes [INFO] ------------------------------------------------------------- [ERROR] COMPILATION ERROR : [INFO] ------------------------------------------------------------- [ERROR] /Users/vshukla/git/Prism/src/main/java/PrenPost/scanUtility.java:[54,52] diamond operator is not supported in -source 1.5 (use -source 7 or higher to enable diamond operator) [ERROR] /Users/vshukla/git/Prism/src/main/java/main/AppUtility.java:[87,86] diamond operator is not supported in -source 1.5 (use -source 7 or higher to enable diamond operator) [ERROR] /Users/vshukla/git/Prism/src/main/java/PrenPost/ComparisionUtility.java:[58,52] diamond operator is not supported in -source 1.5 (use -source 7 or higher to enable diamond operator) [INFO] 3 errors [INFO] ------------------------------------------------------------- [INFO] ------------------------------------------------------------------------ [INFO] BUILD FAILURE [INFO] ------------------------------------------------------------------------ [INFO] Total time: 1.266 s [INFO] Finished at: 2017-03-01T12:11:27+05:30 [INFO] Final Memory: 13M/309M [INFO] ------------------------------------------------------------------------ [ERROR] Failed to execute goal org.apache.maven.plugins:maven-compiler-plugin:3.1:compile (default-compile) on project Maven: Compilation failure: Compilation failure: [ERROR] /Users/vshukla/git/Prism/src/main/java/PrenPost/scanUtility.java:[54,52] diamond operator is not supported in -source 1.5 [ERROR] (use -source 7 or higher to enable diamond operator) [ERROR] /Users/vshukla/git/Prism/src/main/java/main/AppUtility.java:[87,86] diamond operator is not supported in -source 1.5 [ERROR] (use -source 7 or higher to enable diamond operator) [ERROR] /Users/vshukla/git/Prism/src/main/java/PrenPost/ComparisionUtility.java:[58,52] diamond operator is not supported in -source 1.5 [ERROR] (use -source 7 or higher to enable diamond operator) [ERROR] -> [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/MojoFailureException 

但是,下面是项目的构建路径详细信息,显然有JRE – 8设置: 建立路径

和编译设置:

合规水平

无论我构建项目多少次,我都会遇到同样的错误。 即使在清理项目并从日食中刷新它也无济于事。 请指导。

更新:

添加属性后设置maven编译器插件

  1.8 1.8  

我收到以下错误:

 [INFO] Scanning for projects... [INFO] [INFO] ------------------------------------------------------------------------ [INFO] Building Maven 0.0.1-SNAPSHOT [INFO] ------------------------------------------------------------------------ [INFO] [INFO] --- maven-clean-plugin:2.5:clean (default-clean) @ Maven --- [INFO] Deleting /Users/vshukla/git/Prism/target [INFO] [INFO] --- maven-resources-plugin:2.6:resources (default-resources) @ Maven --- [WARNING] Using platform encoding (UTF-8 actually) to copy filtered resources, ie build is platform dependent! [INFO] skip non existing resourceDirectory /Users/vshukla/git/Prism/src/main/resources [INFO] [INFO] --- maven-compiler-plugin:3.1:compile (default-compile) @ Maven --- [INFO] Changes detected - recompiling the module! [WARNING] File encoding has not been set, using platform encoding UTF-8, ie build is platform dependent! [INFO] Compiling 66 source files to /Users/vshukla/git/Prism/target/classes [INFO] ------------------------------------------------------------- [WARNING] COMPILATION WARNING : [INFO] ------------------------------------------------------------- [WARNING] /Users/vshukla/git/Prism/src/main/java/main/MainUITabbed.java: /Users/vshukla/git/Prism/src/main/java/main/MainUITabbed.java uses or overrides a deprecated API. [WARNING] /Users/vshukla/git/Prism/src/main/java/main/MainUITabbed.java: Recompile with -Xlint:deprecation for details. [WARNING] /Users/vshukla/git/Prism/src/main/java/main/MainUITabbed.java: Some input files use unchecked or unsafe operations. [WARNING] /Users/vshukla/git/Prism/src/main/java/main/MainUITabbed.java: Recompile with -Xlint:unchecked for details. [INFO] 4 warnings [INFO] ------------------------------------------------------------- [INFO] ------------------------------------------------------------- [ERROR] COMPILATION ERROR : [INFO] ------------------------------------------------------------- [ERROR] /Users/vshukla/git/Prism/src/main/java/main/MainUITabbed.java:[26,22] package com.apple.eawt does not exist [ERROR] /Users/vshukla/git/Prism/src/main/java/main/MainUITabbed.java:[93,41] cannot find symbol symbol: class Application [ERROR] /Users/vshukla/git/Prism/src/main/java/main/MainUITabbed.java:[93,67] cannot find symbol symbol: variable Application [INFO] 3 errors [INFO] ------------------------------------------------------------- [INFO] ------------------------------------------------------------------------ [INFO] BUILD FAILURE [INFO] ------------------------------------------------------------------------ [INFO] Total time: 2.591 s [INFO] Finished at: 2017-03-01T13:09:47+05:30 [INFO] Final Memory: 21M/347M [INFO] ------------------------------------------------------------------------ [ERROR] Failed to execute goal org.apache.maven.plugins:maven-compiler-plugin:3.1:compile (default-compile) on project Maven: Compilation failure: Compilation failure: [ERROR] /Users/vshukla/git/Prism/src/main/java/main/MainUITabbed.java:[26,22] package com.apple.eawt does not exist [ERROR] /Users/vshukla/git/Prism/src/main/java/main/MainUITabbed.java:[93,41] cannot find symbol [ERROR] symbol: class Application [ERROR] /Users/vshukla/git/Prism/src/main/java/main/MainUITabbed.java:[93,67] cannot find symbol [ERROR] symbol: variable Application [ERROR] -> [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/MojoFailureException 

以下是从MainUITabbed类中提供编译错误的代码片段:

 import com.apple.eawt.Application; public static void main(String[] args) { EventQueue.invokeLater(new Runnable() { public void run() { try { Application application = Application.getApplication(); // line 93 ImageIcon imgicon = new ImageIcon(getClass().getResource( "ICON.jpg")); Image img = imgicon.getImage(); application.setDockIconImage(img); MainUITabbed frame = new MainUITabbed(); frame.setVisible(true); } catch (Exception e) { e.printStackTrace(); } } }); } 

将此添加到POM为我修复它。 请根据需要调整版本

 ...     org.apache.maven.plugins maven-compiler-plugin 3.5.1  1.8 1.8     

我不认为IDE在这里是相关的。 毕竟你正在运行一个Maven,Maven没有一个允许编译钻石操作符的源代码。 所以,我认为你应该配置maven-compiler-plugin本身。

你可以在这里阅读。 但一般来说,尝试添加以下属性:

  1.8 1.8  

并查看它是否仅在Maven中编译。

在我的情况下,它是由与OpenJDK 9(我没有调查过)的不兼容引起的。

如果您不需要JDK 9,那么临时解决方法是从您的计算机中清除它:

 sudo apt-get remove --purge openjdk-9-jdk openjdk-9-jre sudo apt-get remove --purge openjdk-9-jdk-headless openjdk-9-jre-headless 

我有同样的问题,我改变了这个

  1.7 1.7  

这里1.7是我的JDK版本。它已经解决了。

伙伴,
如果每一个都是最新的,那么即使这样你也遇到了这个问题
尝试直接从终端运行此命令,而不是从eclipse运行。
$ mvn clean install

并确保这些事情:

  • maven在系统路径中
  • 所有maven依赖项都可以在`.m2 / repository`中使用
  • java在系统路径中

因为它因为java版本不匹配而来了,所以我已经纠正了它,我能够构建war file.hope它会帮助某人

  1.7 1.7 

在pom.xml文件中执行此操作并在更新项目后,问题就消失了。

  org.apache.maven.plugins maven-compiler-plugin 2.4  1.8 1.8   
  1. 更新下的pom.xml。

  2. 更新您的项目。

  3. 然后清理maven并安装maven。

下面的pom.xml配置使构建成功,并确保项目构建路径JRE系统库应指向Java8。

org.apache.maven.pluginsmaven-compiler-plugin3.7.0 1.81.8

Jdk 9和10解决方案

   org.apache.maven.plugins maven-compiler-plugin ${maven-compiler.version}  ${java.version} ${java.version} true    org.ow2.asm asm 6.2    

并确保您的maven指向JDK 10或9. mvn -v

 Apache Maven 3.5.3 (3383c37e1f9e9b3bc3df5050c29c8aff9f295297; 2018-02-24T14:49:05-05:00) Maven home: C:\devplay\apache-maven-3.5.3\bin\.. Java version: 10.0.1, vendor: Oracle Corporation Java home: C:\Program Files\Java\jdk-10.0.1 Default locale: en_US, platform encoding: Cp1252 OS name: "windows 10", version: "10.0", arch: "amd64", family: "windows" 

您应该将代码添加到pom.xml中,如:

  UTF-8 1.8 1.8  

如果你能够编译mvn compile从终端mvn compile项目成功而不是从Eclipse检查窗口>首选项>已安装的JRE,请确保选择了JDK下的JRE(查看pic中2个不同JRE的路径) ,因为Maven需要JDK来编译,你需要添加它。

已安装的JRE