java - Maven编译错误: (use -source 7 or higher to enable diamond operator)

标签 java maven intellij-idea maven-3

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

相关文章:

Scala 代码在 Intellij 上运行,但不在 Apache Zeppelin notebook 上运行

java - hibernate DAO 错误

java - 在所有上传 Artifact 后,maven 是否始终部署 maven-metadata.xml 文件

java - 使用 TREAT( ... as ... ) 将查询向下转换为子类时出现异常

java - 如何正确地将 jars 组织到 Eclipse 中的一个文件夹中?

java - 资源已在 Eclipse 中加载,但未在 IntelliJ 中加载

java - Servlet 错误 :- 404 Not Found using HTML WEB FORM DATA

java - 生成随机输出 3n+1 问题

java - java中word文档的页数

java - Android如何取消绘图前清除?