我正在尝试编写父pom,并且我定义了一个插件,但我需要更改所有继承实例的配置。所以,我可以在<pluginManagement>
定义中添加一些配置,我可以在<plugin>
中覆盖它,但是如何让孩子们默认返回<pluginManagement>
版本?
<build>
<pluginManagement>
<plugins>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-checkstyle-plugin</artifactId>
<version>2.9.1</version>
<executions...>
<configuration>
<configLocation>
(used by all children)
</configLocation>
</configuration>
</plugin>
</plugins>
</pluginManagement>
<plugins>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-checkstyle-plugin</artifactId>
<configuration>
<configLocation>
(unique to the parent)
</configLocation>
</configuration>
</plugin>
</plugins>
<build>
所以,孩子们继续显示父母的配置会发生什么。
答案 0 :(得分:14)
好的,我想我有。在我的情况下,答案与你指定的内容有关 - 我确实需要标签。但是解决方案是在标签中;通过将其绑定到非阶段,它确实执行。我知道这个。我发现的是必须匹配才能覆盖它。因此,配置永远不会被解析,也无关紧要。
<build>
<pluginManagement>
<plugins>
<plugin>
<!-- Main declaration of the plugin -->
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-checkstyle-plugin</artifactId>
<version>2.9.1</version>
<executions>
<execution>
<!--This must be named-->
<id>checkstyle</id>
<phase>compile</phase>
<goals>
<goal>check</goal>
</goals>
</execution>
</executions>
<configuration...>
</plugin>
</plugins>
</pluginManagement>
<plugins>
<plugin>
<!-- Uses the default config -->
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-checkstyle-plugin</artifactId>
<inherited>false</inherited>
<executions>
<execution>
<!--This matches and thus overrides-->
<id>checkstyle</id>
<phase>none</phase>
</execution>
</executions>
</plugin>
</plugins>
</build>
答案 1 :(得分:9)
您可以在父pom中明确指定不应继承插件:
<build>
<pluginManagement>
<plugins>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-checkstyle-plugin</artifactId>
<version>2.9.1</version>
<executions...>
<configuration>
<configLocation>
(used by all children)
</configLocation>
</configuration>
</plugin>
</plugins>
</pluginManagement>
<plugins>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-checkstyle-plugin</artifactId>
<inherited>false</inherited> <!-- Add this line -->
<configuration>
<configLocation>
(unique to the parent)
</configLocation>
</configuration>
</plugin>
</plugins>
<build>
在您的孩子pom中,您需要指定插件(然后配置将来自<pluginManagement>
父元素。
<build>
<plugins>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-checkstyle-plugin</artifactId>
</plugin>
</plugins>
<build>