千言万语不及官方文档,详情请阅读 compiler:compile 文档
配置 maven 编译插件的 JDK 版本
maven 编译插件(maven-compiler-plugin)有默认编译 JDK 的版本,但这个 JDK 版本通常和我们实际开发使用的不一致。
在 compiler:compile 文档 有2个参数说明了编译 JDK 版本
<source>
The -source argument for the Java compiler.
NOTE: Since 3.8.0 the default value has changed from 1.5 to 1.6
- Type:
java.lang.String
- Since:
2.0
- Required:
No
- User Property:
maven.compiler.source
- Default:
1.6
…
<target>
The -target argument for the Java compiler.
NOTE: Since 3.8.0 the default value has changed from 1.5 to 1.6
- Type:
java.lang.String
- Since:
2.0
- Required:
No
- User Property:
maven.compiler.target
- Default:
1.6
如上所述,从 maven-compiler-plugin3.8.0 之后,默认编译 JDK 版本就由 1.5 改为 1.6 了。但是这仍然跟不上 JDK 的更新速度,目前大多数系统都在使用 JDK1.8
注意:User Property
这个说明,下面会用到
可以在 pom.xml
中这样配置,修改 maven 编译JDK版本
<build>
<plugins>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-compiler-plugin</artifactId>
<version