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.