是五月呀!

maven指定java版本

如果使用Spring Boot搭建项目,可以指定property:

1
2
3
<properties>
<java.version>1.8</java.version>
</properties>

注意java.version这个参数并不是maven提供的,而是Spring Boot特有的。

如果想单纯的使用maven特性指定,那么有两种方式,它们是等价的。
第一种,指定property:

1
2
3
4
<properties>
<maven.compiler.source>1.8</maven.compiler.source>
<maven.compiler.target>1.8</maven.compiler.target>
</properties>

第二种,使用插件:

1
2
3
4
5
6
7
8
9
<plugins>
<plugin>
<artifactId>maven-compiler-plugin</artifactId>
<configuration>
<source>1.8</source>
<target>1.8</target>
</configuration>
</plugin>
</plugins>

插件中的sourcetarget属性就是会使用maven.compiler.sourcemaven.compiler.target,如果你指定的话。

source


The -source argument for the Java compiler.


Default value is: 1.6.


User property is: maven.compiler.source.


target


The -target argument for the Java compiler.


Default value is: 1.6.


User property is: maven.compiler.target.

参考:
Specifying java version in maven - differences between properties and compiler plugin
Setting the -source and -target of the Java Compiler