【问题标题】:Define a Maven plugin configuration in a parent pom and conditionate its activation in children pom在父 pom 中定义一个 Maven 插件配置,并在子 pom 中设置其激活
【发布时间】:2018-10-08 08:26:17
【问题描述】:

我正在构建一个父 pom 来定义用于各种插件的通用版本

<properties>
    <maven-compiler-plugin.version>3.6.0</maven-compiler-plugin.version>
</properties>

<build>
    <pluginManagement>
        <plugins>
            <plugin>
                <artifactId>maven-compiler-plugin</artifactId>
                <version>${maven-compiler-plugin.version}</version>
            </plugin>
        </plugins>
    </pluginManagement>
</build>

但我还想更进一步,定义一些可能被从这个 pom.xml 继承的项目使用的配置文件。 例如,我想预先定义配置以使用 MapStructs

<plugin>
    <artifactId>maven-compiler-plugin</artifactId>
    <configuration>
        <source>${java.version}</source>
        <target>${java.version}</target>
        <showWarnings>true</showWarnings>
        <annotationProcessorPaths>
            <path>
                <groupId>org.mapstruct</groupId>
                <artifactId>mapstruct-processor</artifactId>
                <version>${mapstruct-jdk8.version}</version>
            </path>
        </annotationProcessorPaths>
        <compilerArgs>
            <compilerArg>
                -Amapstruct.defaultComponentModel=spring
            </compilerArg>
            <compilerArg>
                -Amapstruct.unmappedTargetPolicy=ERROR
            </compilerArg>
        </compilerArgs>
    </configuration>
</plugin>

我将如何在父 pom 中对此进行编码,以便子 pom 可以选择是否使用该特定配置,具体取决于他们是否需要使用 mapstruct ?

【问题讨论】:

  • 您可以在 Maven 中定义 profiles 使用引用属性的 activation 元素(例如,在父级中默认为 false)并让子级设置不同的激活密钥值。

标签: java maven inheritance pom.xml maven-plugin


【解决方案1】:

使用&lt;skip&gt; 的配置可以在子 POM 中使用:

 <configuration>
      <skip>true</skip>
 </configuration>

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 2016-01-19
    • 2016-05-07
    • 1970-01-01
    • 1970-01-01
    • 2014-07-22
    • 2010-12-11
    • 1970-01-01
    • 2011-06-17
    相关资源
    最近更新 更多