解决:Java source1.6不支持diamond运算符,请使用source 7或更高版本以启用diamond运算符

diamond运算符,指的是JDK1.7的一个新特性。Maven默认用的是JDK1.6去编译。所以需要配置成更高的版本,有以下几种解决办法:

1.在项目pom.xml中加入下面的配置即可

<properties>
    <maven.compiler.source>1.8</maven.compiler.source>
    <maven.compiler.target>1.8</maven.compiler.target>
</properties>

2.直接在pom.xml中配置Maven的编译插件

<build>
    <plugins>
        <plugin>
            <groupId>org.apache.maven.plugins</groupId>
            <artifactId>maven-compiler-plugin</artifactId>
            <version>3.5.1</version>
            <configuration>
                <source>1.8</source>
                <target>1.8</target>
            </configuration>
        </plugin>
    </plugins>
</build>

3.在配置的maven安装包的setting.xml中的profiles标签中加入以下标签

<profile>
    <id>jdk-1.8</id>
    <activation>
        <activeByDefault>true</activeByDefault>
        <jdk>1.8</jdk>
    </activation>
    <properties>
        <maven.compiler.source>1.8</maven.compiler.source>
        <maven.compiler.target>1.8</maven.compiler.target>
        <maven.compiler.compilerVersion>1.8</maven.compiler.compilerVersion>
    </properties>
</profile>

猜你喜欢

转载自www.cnblogs.com/zsg88/p/11015292.html