禁用父 POM 中定义的 Maven 插件

问题描述 投票:0回答:4

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

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

maven maven-2
4个回答
260
投票

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

对于插件。


78
投票

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

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

40
投票

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

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

我想强调的2点:

  1. phase 设置为Nothing,这看起来比“none”没那么hacky,尽管仍然是一个hack。
  2. id 必须与您要覆盖的执行相同。如果你没有指定 id 来执行,Maven 将隐式地执行它(以你直觉上不期望的方式)。

发帖后发现它已经在stackoverflow中了: 在 Maven 多模块项目中,如何禁用一个子项目中的插件?


3
投票

我知道这个帖子确实很旧,但 @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>
© www.soinside.com 2019 - 2024. All rights reserved.