我在IntelliJ中使用maven,JDK1.8,maven 3.2.5。获取编译错误:使用-source 7或更高版本启用diamond opera。具体如下:
[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或更高版本:
maven-compiler-plugin
<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>