在pom.xml
,定义了此maven.compiler.source
属性,以告知Maven使用Java 8编译项目。
1. Maven属性
Java 8
pom.xml
<properties>
<maven.compiler.target>1.8</maven.compiler.target>
<maven.compiler.source>1.8</maven.compiler.source>
</properties>
Java 7
pom.xml
<properties>
<maven.compiler.target>1.7</maven.compiler.target>
<maven.compiler.source>1.7</maven.compiler.source>
</properties>
2.编译器插件
或者,直接配置插件。
pom.xml
<build>
<plugins>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-compiler-plugin</artifactId>
<version>3.6.1</version>
<configuration>
<source>1.8</source>
<target>1.8</target>
</configuration>
</plugin>
</plugins>
</build>
参考文献
翻译自: https://mkyong.com/maven/how-to-tell-maven-to-use-java-8/