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

解决: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>
复制代码
为人:谦逊、激情、博学、审问、慎思、明辨、 笃行
学问:纸上得来终觉浅,绝知此事要躬行
为事:工欲善其事,必先利其器。
态度:道阻且长,行则将至;行而不辍,未来可期
转载请标注出处!
原文地址:https://www.cnblogs.com/ios9/p/15074565.html