rog*_*hat 29 java build maven maven-compiler-plugin
我有一个maven项目分叉并从git repo克隆到我的eclipse上.它建立在Java 8之上.我做的第一件事是执行a
mvn clean install
Run Code Online (Sandbox Code Playgroud)
但我收到以下失败消息:
[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, i.e. 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, i.e. 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
Run Code Online (Sandbox Code Playgroud)
但是,下面是项目的构建路径详细信息,显然有JRE - 8设置:

和编译设置:
无论我构建项目多少次,我都会遇到同样的错误.即使在清理项目并从日食中刷新它也无济于事.请指导.
更新:
添加属性后设置maven编译器插件
<properties>
<maven.compiler.source>1.8</maven.compiler.source>
<maven.compiler.target>1.8</maven.compiler.target>
</properties>
Run Code Online (Sandbox Code Playgroud)
,
我收到以下错误:
[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, i.e. 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, i.e. 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
Run Code Online (Sandbox Code Playgroud)
以下是从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();
}
}
});
}
Run Code Online (Sandbox Code Playgroud)
小智 48
将此添加到POM为我修复它.请根据需要调整版本
...
</dependencies>
<build>
<plugins>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-compiler-plugin</artifactId>
<version>3.5.1</version>
<configuration>
<source>1.8</source>
<target>1.8</target>
</configuration>
</plugin>
</plugins>
</build>
Run Code Online (Sandbox Code Playgroud)
Mar*_*nik 14
我不认为IDE在这里是相关的.毕竟你正在运行一个Maven,Maven没有一个允许编译钻石操作符的源代码.所以,我认为你应该配置maven-compiler-plugin本身.
你可以在这里阅读这个.但一般来说,尝试添加以下属性:
<properties>
<maven.compiler.source>1.8</maven.compiler.source>
<maven.compiler.target>1.8</maven.compiler.target>
</properties>
Run Code Online (Sandbox Code Playgroud)
并查看它是否仅在Maven中编译.
小智 6
您应该将代码添加到 pom.xml 中,例如:
<properties>
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
<maven.compiler.source>1.8</maven.compiler.source>
<maven.compiler.target>1.8</maven.compiler.target>
</properties>
Run Code Online (Sandbox Code Playgroud)
这是一个令人恼火的错误,偶尔会弹出,记下一些有助于:
无论是通过 Intellij 还是命令行,从 Eclipse 角度编写答案作为基本逻辑都将保持不变
Run Code Online (Sandbox Code Playgroud)<maven.compiler.source>1.8</maven.compiler.source> <maven.compiler.target>1.8</maven.compiler.target>
在某些情况下,您将开始看到错误,因为我们尝试强制更新说, 无法从 Y 路径传输 X 依赖项,将不会重新尝试解决方案,bla bla bla
在这种情况下,通过 cd 快速将其修复到 .m2/repository 文件夹并运行以下命令:
Run Code Online (Sandbox Code Playgroud)for /r %i in (*.lastUpdated) do del %i
就我而言,它是由与 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
Run Code Online (Sandbox Code Playgroud)
兄弟,
如果每一个都是最新的,即使你遇到这个问题,那么
尝试直接从终端运行这个命令,而不是从 eclipse 运行。
$ mvn clean install
并确保这些事情:
确保 java 主路径正确。就我而言,pom 文件中的 java 主路径是错误的。
<properties>
<java.home>/usr/java/jdk1.8.0_45/bin/javac</java.home>
</properties>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-compiler-plugin</artifactId>
<version>3.5.1</version>
<configuration>
<verbose>true</verbose>
<fork>true</fork>
<executable>${java.home}</executable>
<compilerVersion>1.8</compilerVersion>
<source>1.8</source>
<target>1.8</target>
</configuration>
</plugin>
Run Code Online (Sandbox Code Playgroud)
如果你的本地jdk版本是11或者9、10,你项目的java源/目标版本是1.8,并且你使用的是org.projectlombok:lombokpackage,那么你可以尝试更新它的版本到1.16.22或者1.18.12,像这样:
<dependency>
<groupId>org.projectlombok</groupId>
<artifactId>lombok</artifactId>
<version>1.16.22</version>
</dependency>
Run Code Online (Sandbox Code Playgroud)
它刚刚解决了我的问题。
<maven.compiler.release>(不是source&target)其他几个答案显示<maven.compiler.source>& <maven.compiler.target>。现在,这两个元素都被更简单的单个元素所取代:<maven.compiler.release>。
<maven.compiler.release>15</maven.compiler.release>\nRun Code Online (Sandbox Code Playgroud)\n所以这:
\n <!--old-school-->\n <properties>\n <project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>\n <maven.compiler.source>15</maven.compiler.source>\n <maven.compiler.target>15</maven.compiler.target>\n </properties>\nRun Code Online (Sandbox Code Playgroud)\n\xe2\x80\xa6 变为:
\n <!--modern-->\n <properties>\n <project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>\n <maven.compiler.release>15</maven.compiler.release>\n </properties>\nRun Code Online (Sandbox Code Playgroud)\n请参阅问题,\xe2\x80\x9cmaven.compiler.release\xe2\x80\x9d 作为源和目标的替代品?
\n| 归档时间: |
|
| 查看次数: |
261475 次 |
| 最近记录: |