26

我正在尝试编写一个父 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>

所以,发生的事情是孩子继续显示父母的配置。

4

2 回答 2

17

好的,我想我有它。就我而言,答案与您指定的内容有关 - 我确实需要标签。但是解决方案在标签中;通过将其绑定到非阶段,它会执行。这是我知道的。我发现必须匹配才能覆盖它。因此,配置永远不会被解析并且无关紧要。

<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>
于 2013-02-01T18:50:53.967 回答
12

您可以在父 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>
于 2013-02-01T14:49:54.730 回答