使用Maven时,父子插件配置继承出现问题

27

我想编写一个父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>

所以,发生的情况是孩子们继续显示父级配置。


这个回答解决了您的问题吗?【在父POM中定义Maven插件,但仅在子项目中调用插件】(https://dev59.com/dGcs5IYBdhLWcg3wWCpB) - zypA13510
2个回答

18

好的,我想我明白了。在我的情况下,答案与您指定的相关 - 我确实需要使用“<h:form>”标签。然而,解决方案在“<f:ajax>”标签中;通过将其绑定到非相位,则会执行它。这一点我知道。我发现的是,“<f:ajax>”和“<h:commandButton>”必须匹配才能覆盖。“<h:commandButton>”没有被解析,也不重要。

<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>

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>

4
没错,这是正确的。然而,它意味着在每个子级中都要明确指定插件。我喜欢的想法是可以自动从父级继承。 - end-user

网页内容由stack overflow 提供, 点击上面的
可以查看英文原文,
原文链接