Maven在java 7项目中抱怨“使用-source 7或更高版本来启用钻石操作符”

时间:2015-07-30 00:12:23

标签: 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>

...等

1 个答案:

答案 0 :(得分:3)

通常,IDE使用maven pom.xml文件作为项目配置的源。 在IDE中更改编译器设置并不总是对maven构建有效。 保持项目始终可以通过maven管理的最佳方法是编辑pom.xml文件并指示IDE与maven同步。

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

  1. 在pom.xml中配置maven编译器插件
  2.     <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设置”那样可能是个好看的地方。
相关问题