java - Maven 在 Java 7 项目中提示 "use -source 7 or higher to enable diamond operator"

标签 java maven

<分区>

我在项目中使用 Java 7 语法,但是当我转到 mvn clean install 时,maven 告诉我:

[ERROR] /Users/mosawi/Perforce/src/main/java/com/generalatomics/compilers/Engine.java:[47,45] diamond operator is not supported in -source 1.5
[ERROR] (use -source 7 or higher to enable diamond operator)

我很确定我的项目是 Java 7,我的 java 构建路径设置为 Java 7

enter image description here

编辑:

这是关于我的 pom.xml 的相关信息 ...等等

<reporting>
    <plugins>
        <plugin>
            <groupId>org.apache.maven.plugins</groupId>
            <artifactId>maven-project-info-reports-plugin</artifactId>
            <version>2.8</version>
            <configuration>
                <dependencyLocationsEnabled>true</dependencyLocationsEnabled>
            </configuration>
        </plugin>
        <plugin>
            <groupId>org.codehaus.mojo</groupId>
            <artifactId>cobertura-maven-plugin</artifactId>
            <version>2.7</version>
            <configuration>
                <formats>
                    <format>html</format>
                    <format>xml</format>
                </formats>
            </configuration>
        </plugin>
    </plugins>
</reporting>

...等等

最佳答案

通常 IDE 使用 maven pom.xml 文件作为项目配置的来源。 在 IDE 中更改编译器设置并不总是对 Maven 构建有影响。 使项目始终易于使用 Maven 进行管理的最佳方法是编辑 pom.xml 文件并指示 IDE 与 Maven 同步。

在这种特殊情况下,您必须检查两件事:

  1. 在pom.xml中配置maven编译器插件
    <build>

    <plugins>
        <plugin>
            <artifactId>maven-compiler-plugin</artifactId>
            <configuration>
                <source>1.7</source>
                <target>1.7</target>
            </configuration>
        </plugin>
    </plugins>
    ...
  1. 确保 mvn clean 命令实际上是用 jdk7 启动的(如果您从 IDE 启动它,“Maven 设置”之类的东西可能是一个不错的地方。

关于java - Maven 在 Java 7 项目中提示 "use -source 7 or higher to enable diamond operator",我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/31713244/

相关文章:

java - maven 未在 Eclipse 中下载 iText jar 依赖项

java - JTable 排序不显示图像

java - Java Swing 对象静态初始化的首选习惯用法?

java - 玩2.0(java): Is MongoDB suitable for hotel booking web app?

java - Maven项目编译错误: cannot find symbol (which is java. lang.String)

Maven 无法在同一个 repo 中传输许多 Artifact 之一

java - Google 云端硬盘无法从其他设备访问数据

java - 无法在方法中访问数组?

java - 将不同语言的服务部署到同一个应用程序 [Google App Engine]

maven-2 - 使用 Maven 为多个 java 架构构建 Artifact (有什么比配置文件更好的)?