【发布时间】: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