Maven 编译错误:(使用 -source 7 或更高版本来启用菱形运算符)
问题描述:
我在 IntelliJ、JDK1.8、maven 3.2.5 中使用 maven.出现编译错误:使用 -source 7 或更高版本来启用钻石歌剧.详情如下:
I'm using maven in IntelliJ, JDK1.8, maven 3.2.5. Got compilation error: use -source 7 or higher to enable diamond opera. details are as follows:
[ERROR] COMPILATION ERROR :
[INFO] -------------------------------------------------------------
[ERROR] TrainingConstructor.java:[31,55] diamond operator is not supported in -source 1.5 (use -source 7 or higher to enable diamond operator)
[ERROR] DTM.java:[79,21] try-with-resources is not supported in -source 1.5 (use -source 7 or higher to enable try-with-resources)
[ERROR] ticons.java:[53,44] diamond operator is not supported in -source 1.5 (use -source 7 or higher to enable diamond operator)
有什么建议吗?是否还有其他配置可以设置此 -source 级别?似乎它不使用 java 1.8.
Any suggestions? Is there any other configuration to set this -source level? seems it doesn't use java 1.8.
答
检查你的 maven-compiler-plugin
是如何配置的,它应该使用 java 7 或更高版本:
Check how your maven-compiler-plugin
is configured, it should use java version 7 or higher:
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-compiler-plugin</artifactId>
<version>3.1</version>
<configuration>
<source>1.7</source>
<target>1.7</target>
</configuration>
</plugin>
要获得更完整的答案,请参阅以下内容.
For a more complete answer see the one below.