我在IntelliJ、JDK1.8、maven 3.2.5中使用maven。出现编译错误:使用 -source 7 或更高版本启用钻石歌剧。详情如下:
[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)
有什么建议吗?是否有其他配置来设置此源级别?似乎它不使用java 1.8。
最佳答案
检查您的 maven-compiler-plugin
的配置方式,它应该使用 java 版本 7 或更高版本:
<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>
有关更完整的答案,请参阅 the one below .
关于java - Maven编译错误: (use -source 7 or higher to enable diamond operator),我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/57951045/