我维护了大量从父pom继承的子Maven pom,但目前只定义了继承的依赖项。我现在正在实现插件继承。在我的一个服务中,我只是逐步通过插件,将块复制到我的父pom,并让子pom指定groupId
和artifactId
。在有效的pom中,它正确地得到了继承的插件版本。到目前为止,所有需要的配置都已经在父插件中定义了。我现在正在处理一个子插件定义了一个configuration
块的插件。在这个例子中,父插件甚至没有定义一个configuration
块,但是它定义了几个executions
块,其看起来被正确地继承。
我在有效pom中看到的是configuration
块总是从父pom中取出。子pom configuration
块被忽略。最初,父pom有一个空的configuration
块,子pom中的结果块也是空的,忽略了子pom中的内容。然后我向父pom添加了一些虚拟配置,这在子pom中得到了回应。再次忽略儿童POM。
我原以为默认设置是“子覆盖”,但似乎不是这样。
我试着暂时从父插件中删除插件定义,这样就修复了子插件,使用了子pom中的配置块。
我使用的是Maven 3.8.2。我现在正在开发的插件是jacoco-maven-plugin
,但我想这是无关紧要的。
这是来自父级的plugin
块(在pluginManagement
内):
<plugin>
<groupId>org.jacoco</groupId>
<artifactId>jacoco-maven-plugin</artifactId>
<version>${jacoco.maven.plugin.version}</version>
<configuration>
<excludes> <exclude>abc</exclude> </excludes>
</configuration>
<executions>
<execution>
<id>pre-unit-test</id>
<goals> <goal>prepare-agent</goal> </goals>
<configuration>
<propertyName>surefireArgLine</propertyName>
</configuration>
</execution>
<execution>
<id>post-unit-test</id>
<phase>test</phase>
<goals> <goal>report</goal> </goals>
<configuration>
<outputDirectory>${jacoco.path}</outputDirectory>
</configuration>
</execution>
<execution>
<id>pre-integration-test</id>
<phase>pre-integration-test</phase>
<goals> <goal>prepare-agent</goal> </goals>
<configuration>
<destFile>${sonar.jacoco.itReportPath}</destFile>
<propertyName>failsafeArgLine</propertyName>
</configuration>
</execution>
<execution>
<id>post-integration-test</id>
<phase>post-integration-test</phase>
<goals> <goal>report</goal> </goals>
<configuration>
<dataFile>${sonar.jacoco.itReportPath}/</dataFile>
<outputDirectory>${jacoco.itPath}</outputDirectory>
</configuration>
</execution>
</executions>
</plugin>
下面是子pom.xml中的内容:
<plugin>
<groupId>org.jacoco</groupId>
<artifactId>jacoco-maven-plugin</artifactId>
<configuration>
<excludes>
<exclude>{specificpath}</exclude>
...
</excludes>
</configuration>
</plugin>
注意“{specificpath}”只是一个占位符,它在pom.xml中有一个有效的路径。
这就是有效pom的最终结果(同样,有些省略):
<plugin>
<groupId>org.jacoco</groupId>
<artifactId>jacoco-maven-plugin</artifactId>
<version>0.8.5</version>
<executions>
<execution>
<id>pre-unit-test</id>
<goals>
<goal>prepare-agent</goal>
</goals>
<configuration>
<propertyName>surefireArgLine</propertyName>
<excludes>
<exclude>abc</exclude>
</excludes>
</configuration>
</execution>
<execution>
<id>post-unit-test</id>
<phase>test</phase>
<goals>
<goal>report</goal>
</goals>
<configuration>
<outputDirectory>.../target/jacoco_report</outputDirectory>
<excludes>
<exclude>abc</exclude>
</excludes>
</configuration>
</execution>
<execution>
<id>pre-integration-test</id>
<phase>pre-integration-test</phase>
<goals>
<goal>prepare-agent</goal>
</goals>
<configuration>
<destFile>${sonar.jacoco.itReportPath}</destFile>
<propertyName>failsafeArgLine</propertyName>
<excludes>
<exclude>abc</exclude>
</excludes>
</configuration>
</execution>
<execution>
<id>post-integration-test</id>
<phase>post-integration-test</phase>
<goals>
<goal>report</goal>
</goals>
<configuration>
<dataFile>${sonar.jacoco.itReportPath}/</dataFile>
<outputDirectory>.../target/jacoco_itReport</outputDirectory>
<excludes>
<exclude>abc</exclude>
</excludes>
</configuration>
</execution>
</executions>
<configuration>
<excludes>
<exclude>abc</exclude>
</excludes>
</configuration>
</plugin>
您会注意到,整个配置中只有abc
从父级中排除,而没有{specificpath}
从子级中排除,abc
排除也被推送到每个execution
块中的configuration
块中。
在我看来,这个问题很可能与每个execution
块中都有configuration
块这一事实有关,但我不知道该怎么办。
如果我暂时删除父pom中的plugin
定义,并将其全部恢复到子pom中,则在有效pom中会得到以下内容:
<plugin>
<groupId>org.jacoco</groupId>
<artifactId>jacoco-maven-plugin</artifactId>
<version>0.8.8</version>
<executions>
<execution>
<id>pre-unit-test</id>
<goals>
<goal>prepare-agent</goal>
</goals>
<configuration>
<propertyName>surefireArgLine</propertyName>
<excludes>
<exclude>{specificpath}</exclude>
...
</excludes>
</configuration>
</execution>
<execution>
<id>post-unit-test</id>
<phase>test</phase>
<goals>
<goal>report</goal>
</goals>
<configuration>
<outputDirectory>.../target/jacoco_report</outputDirectory>
<excludes>
<exclude>{specificpath}</exclude>
...
</excludes>
</configuration>
</execution>
<execution>
<id>pre-integration-test</id>
<phase>pre-integration-test</phase>
<goals>
<goal>prepare-agent</goal>
</goals>
<configuration>
<destFile>${sonar.jacoco.itReportPath}</destFile>
<propertyName>failsafeArgLine</propertyName>
<excludes>
<exclude>{specificpath}</exclude>
...
</excludes>
</configuration>
</execution>
<execution>
<id>post-integration-test</id>
<phase>post-integration-test</phase>
<goals>
<goal>report</goal>
</goals>
<configuration>
<dataFile>${sonar.jacoco.itReportPath}/</dataFile>
<outputDirectory>.../target/jacoco_itReport</outputDirectory>
<excludes>
<exclude>{specificpath}</exclude>
...
</excludes>
</configuration>
</execution>
</executions>
<configuration>
<excludes>
<exclude>{specificpath}</exclude>
...
</excludes>
</configuration>
</plugin>
1条答案
按热度按时间cuxqih211#
我不能说配置地狱出了什么问题。
我能说的是,通常最好使用属性(如
${some.prop}
)在父对象中定义配置,然后覆盖子对象(<properties><some.prop>C:\mydir</some.prop></properties>
)中的属性。