maven 出现错误 -source 1.5 中不支持 diamond 运算符

2023-06-12,,

mvn clean package -DskipTests

出现如下错误:

-source 1.5 中不支持 diamond 运算符 
[ERROR] (请使用 -source 7 或更高版本以启用 diamond 运算符)

解决方法1:pom.xml文件中添加

<plugins>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-compiler-plugin</artifactId>
<version>3.1</version>
<configuration>
<source>1.7</source>
<target>1.7</target>
<encoding>UTF-</encoding>
</configuration>
</plugin>
</plugins>

解决方法2:maven 的/conf/settings.xml添加

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

maven 出现错误 -source 1.5 中不支持 diamond 运算符的相关教程结束。

《maven 出现错误 -source 1.5 中不支持 diamond 运算符.doc》

下载本文的Word格式文档,以方便收藏与打印。