【问题标题】:Disable a Maven plugin defined in a parent POM禁用父 POM 中定义的 Maven 插件
【发布时间】:2011-12-10 21:24:43
【问题描述】:

我正在使用一个父 POM,它定义了一个我不想在子 POM 中运行的插件。如何完全禁用子 pom 中的插件?

约束:我无法更改父 POM 本身。

【问题讨论】:

    标签: maven maven-2


    【解决方案1】:

    在子 POM 中禁用 Findbugs 时,以下对我有用:

    <plugin>
        <groupId>org.codehaus.mojo</groupId>
        <artifactId>findbugs-maven-plugin</artifactId>
        <executions>
            <execution>
                <id>ID_AS_IN_PARENT</id> <!-- id is necessary sometimes -->
                <phase>none</phase>
            </execution>
        </executions>
    </plugin>
    

    注意:Findbugs 插件的完整定义在我们的父/超级 POM 中,因此它将继承版本等。

    在 Maven 3 中,您需要使用:

     <configuration>
          <skip>true</skip>
     </configuration>
    

    插件。

    【讨论】:

    • 虽然这是“正确的”,即它可以工作,但应该注意它是一个未指定(或至少 未记录)的功能。没有称为“无”的官方阶段。所以,你不妨把 'foo' 放在那里。
    • 对 Maven 3 中的我来说,这不起作用。 true 喜欢 bmargulies 建议的作品
    • 我必须添加父 POM 的 &lt;id&gt;…&lt;/id&gt; 部分,然后它对我有用。
    • Maven 3 解决方案并没有真正禁用插件,是吗?根据输出,插件仍在执行。然后它是否尊重跳过配置,以及它选择跳过的方式/内容,似乎取决于各个插件。
    • mirabilos 的评论是 Maven 3 的正确解决方案,并且可以跨所有插件移植。并非所有插件都有&lt;skip&gt; 参数。
    【解决方案2】:

    查看插件是否有“跳过”配置参数。几乎所有人都这样做。如果是这样,只需将其添加到子声明中:

    <plugin>
       <groupId>group</groupId>
       <artifactId>artifact</artifactId>
       <configuration>
         <skip>true</skip>
       </configuration>
    </plugin>
    

    如果没有,则使用:

    <plugin>    
    <groupId>group</groupId>   
     <artifactId>artifact</artifactId>    
    <executions>
         <execution>
           <id>TheNameOfTheRelevantExecution</id>
           <phase>none</phase>
         </execution>    
    </executions>  
    </plugin>
    

    【讨论】:

    • 如何命名您正在使用的插件,并运行 help:effective-pom 以查看您是否真的执行正确。
    • 还要注意插件与插件管理。后者覆盖前者。
    • 我正在使用 Cobertura 插件,我不想在子 pom 中运行它。
    • 检查目标在 2.5 中有一个跳过。以前没有。 cobertura 目标没有。
    • 对于那些使用 Tiles Maven 插件 并考虑使用第二个选项(通过 ID 覆盖执行)的人的重要说明:在 tile 内的插件 changes execution IDs 以反映 tile GAV坐标。所以为了覆盖工作&lt;configuration tiles-keep-id="true" /&gt;标签应该添加到执行中以保留指定的执行ID。
    【解决方案3】:

    线程很旧,但也许有人仍然感兴趣。 我发现的最短形式是对 λlex 和 bmargulies 示例的进一步改进。执行标签将如下所示:

    <execution>
        <id>TheNameOfTheRelevantExecution</id>
        <phase/>
    </execution>
    

    我要强调的两点:

    1. phase 设置为空,看起来比“none”少hacky,但仍然是hack。
    2. id 必须与您要覆盖的执行相同。如果您不指定执行的 id,Maven 会隐式执行(以您不期望的方式)。

    发布后发现它已经在stackoverflow中: In a Maven multi-module project, how can I disable a plugin in one child?

    【讨论】:

    • 备案:默认执行 ID 遵循此答案中列出的简单规则:stackoverflow.com/a/34599117/7641
    • 值得注意的是,这个解决方案实际上 disables(正如 OP 要求的那样)插件(对于给定的执行 ID),而不是依赖于插件特定的“跳过”选项。
    【解决方案4】:

    我知道这个帖子真的很旧,但@Ivan Bondarenko 的解决方案在我的情况下帮助了我。

    我的pom.xml 中有以下内容。

    <build>
        ...
        <plugins>
             <plugin>
                    <groupId>com.consol.citrus</groupId>
                    <artifactId>citrus-remote-maven-plugin</artifactId>
                    <version>${citrus.version}</version>
                    <executions>
                        <execution>
                            <id>generate-citrus-war</id>
                            <goals>
                                <goal>test-war</goal>
                            </goals>
                        </execution>
                    </executions>
                </plugin>
        </plugins>
    </build>
    

    我想要的是为特定配置文件禁用generate-citrus-war 的执行,这就是解决方案:

    <profile>
        <id>it</id>
        <build>
            <plugins>
                <plugin>
                    <groupId>com.consol.citrus</groupId>
                    <artifactId>citrus-remote-maven-plugin</artifactId>
                    <version>${citrus.version}</version>
                    <executions>
                        <!-- disable generating the war for this profile -->
                        <execution>
                            <id>generate-citrus-war</id>
                            <phase/>
                        </execution>
    
                        <!-- do something else -->
                        <execution>
                            ...
                        </execution>
                    </executions>
                </plugin>
            </plugins>
        </build>
    </profile>
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2011-06-17
      • 1970-01-01
      • 2012-10-07
      • 2011-12-05
      • 2021-12-13
      • 2018-10-08
      • 2016-01-19
      • 1970-01-01
      相关资源
      最近更新 更多