【问题标题】:Difference between maven compiler in properties tag and maven compiler in plugin tag in pom.xml [duplicate]pom.xml中properties标签中的maven编译器和plugin标签中的maven编译器之间的区别[重复]
【发布时间】:2020-03-24 15:18:21
【问题描述】:

我试图在我的 pom.xml 中将我的项目源和目标设置为 Java 1.8,并发现它可以通过两种方式完成:

  1. 在属性标签中设置:

    <maven.compiler.target>1.8</maven.compiler.target>
    <maven.compiler.source>1.8</maven.compiler.source>
    
  2. 在插件中配置:

    <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 pom.xml maven-plugin


    【解决方案1】:

    是等价的。实际上 maven-compiler-plugin 的 标签使用 属性,而 使用属性 属性:https://maven.apache.org/plugins/maven-compiler-plugin/compile-mojo.html

    所以如果你只想设置这两个属性,你可以愉快地使用属性,但是插件更灵活,因为它有很多其他可以设置的配置(在野外我见过:fork, annotationProcessors、compilerArgs 等标签)

    【讨论】:

      猜你喜欢
      • 2023-04-06
      • 2019-02-28
      • 1970-01-01
      • 2016-05-02
      • 2021-04-18
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多