本文介绍了在Maven父/子插件配置继承中苦苦挣扎的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在尝试编写父pom,并且我已经定义了一个插件,但我需要更改所有继承实例的配置。所以,我可以在< pluginManagement> 定义中添加一些配置,我可以在< plugin> ,但如何让孩子们默认回到< pluginManagement> 版本?

I'm trying to write a parent pom, and I have a plugin defined, but I need to change the config for all inherited instances. So, I can put some configuration in the <pluginManagement> definition, and I can override it in the <plugin>, but how do I get the children to default back to the <pluginManagement> version?

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

所以,孩子们继续显示父母的配置会发生什么。

So, what happens is the children continue to show the parent's config.

推荐答案

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

Ok, I think I have it. The answer, in my case, relates to what you specified - I did need the tag. However the solution was in the tag; by binding it to a non-phase, it does execute. This I knew. What I discovered is that the had to match in order for it to override. Thus, the config never gets parsed and doesn't matter.

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

这篇关于在Maven父/子插件配置继承中苦苦挣扎的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

08-20 19:31