小编典典

Maven编译错误:(使用-source 7或更高版本启用diamond运算符)

java

我在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。


阅读 738

收藏
2020-03-20

共1个答案

小编典典

检查你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>
2020-03-20