pom.xml 中 properties 标签中的 maven 编译器和 plugin 标签中的 maven 编译器的区别
Difference between maven compiler in properties tag and maven compiler in plugin tag in pom.xml
我试图在我的 pom.xml 中将我的项目源和目标设置为 Java 1.8 并发现它可以通过两种方式完成:
在属性标签中设置:
<maven.compiler.target>1.8</maven.compiler.target>
<maven.compiler.source>1.8</maven.compiler.source>
在插件中配置:
<build>
<pluginManagement>
<plugins>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-compiler-plugin</artifactId>
<version>3.8.1</version>
<configuration>
<source>1.8</source>
<target>1.8</target>
</configuration>
</plugin>
</plugins>
</pluginManagement>
如果可以选择,我更喜欢选项 #1,因为它更短,但两者之间的真正区别是什么?
是等价的。事实上 maven-compiler-plugin 的 标签使用 属性 而 使用 属性 属性: https://maven.apache.org/plugins/maven-compiler-plugin/compile-mojo.html
所以如果你只想设置这两个属性,你可以愉快地使用属性,但插件更灵活,因为它有很多其他配置可以设置(在野外我看到: fork、annotationProcessors、compilerArgs 和其他标签)
我试图在我的 pom.xml 中将我的项目源和目标设置为 Java 1.8 并发现它可以通过两种方式完成:
在属性标签中设置:
<maven.compiler.target>1.8</maven.compiler.target> <maven.compiler.source>1.8</maven.compiler.source>
在插件中配置:
<build> <pluginManagement> <plugins> <plugin> <groupId>org.apache.maven.plugins</groupId> <artifactId>maven-compiler-plugin</artifactId> <version>3.8.1</version> <configuration> <source>1.8</source> <target>1.8</target> </configuration> </plugin> </plugins> </pluginManagement>
如果可以选择,我更喜欢选项 #1,因为它更短,但两者之间的真正区别是什么?
是等价的。事实上 maven-compiler-plugin 的
所以如果你只想设置这两个属性,你可以愉快地使用属性,但插件更灵活,因为它有很多其他配置可以设置(在野外我看到: fork、annotationProcessors、compilerArgs 和其他标签)