错误:在maven install是抛出 “1.5不支持diamond运算符,请使用source 7或更高版本以启用diamond运算符”

Maven默认用的是JDK1.5去编译

diamond运算符,有的书翻译为菱形,有的书写的是钻石语法,指的是JDK1.7的一个新特性

List<String> list = new ArrayList<String>(); // 老版本写法
List<String> list = new ArrayList<>(); // JDK1.7写法

所以Maven默认使用JDK1.5去编译肯定是不认识这个东西的

你可以在pom.xml中加入下面的东西即可

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

或者你直接在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>

 

posted @ 2017-07-29 21:41  大大大圣  阅读(8456)  评论(0编辑  收藏  举报