您的位置:首页 > 其它

Maven install时抛出“1.5不支持diamond运算符,请使用source 7或更高版本以启用diamond运算符”

2018-01-05 15:59 495 查看
 错误:在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.7</maven.compiler.source>
<maven.compiler.target>1.7</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.7</source>
<target>1.7</target>
</configuration>
</plugin>
</plugins>
</build>
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: 
相关文章推荐