ChatGPT解决这个技术问题 Extra ChatGPT

Disable a Maven plugin defined in a parent POM

I am using a parent POM that defines a plugin that I do not want to be run in a child POM. How can I disable the plugin in the child pom completely?

Constraint: I cannot change the parent POM itself.


A
Alex

The following works for me when disabling Findbugs in a child POM:

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

Note: the full definition of the Findbugs plugin is in our parent/super POM, so it'll inherit the version and so-on.

In Maven 3, you'll need to use:

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

for the plugin.


While this is "correct" i.e. it works it should be noted that it's an unspecified (or at least undocumented) feature. There's no official phase called 'none'. So, you might as well put 'foo' there.
For me in Maven 3 this doesn't work. true like bmargulies suggested works
I had to add the <id>…</id> part of the parent POM, then it worked for me.
The Maven 3 solution doesn't really disable the plugin though, does it? According to the output, the plugin is still executed. Whether it then respects the skip configuration, and how/what it chooses to skip, appears to be up to the individual plugin.
mirabilos's comment is the correct solution for Maven 3 and is portable across all plugins. Not all plugins have a <skip> parameter.
b
bmargulies

See if the plugin has a 'skip' configuration parameter. Nearly all do. if it does, just add it to a declaration in the child:

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

If not, then use:

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

How about naming the plugin you are working with, and running help:effective-pom to see if you really have the execution correct.
Also look out for plugins versus pluginManagement. The later overrides the former.
I am using the Cobertura plugin and I do not want to run it in the child pom.
The check goal has a skip in 2.5. It didn't before. The cobertura goal does not.
Important note for those, who use Tiles Maven Plugin and considering to use second option (override execution by ID): the plugin changes execution IDs inside the tile to reflect tile GAV coordinates. So in order for override to work <configuration tiles-keep-id="true" /> tag should be added to the execution to preserve specified execution ID.
A
Alex

The thread is old, but maybe someone is still interested. The shortest form I found is further improvement on the example from λlex and bmargulies. The execution tag will look like:

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

2 points I want to highlight:

phase is set to nothing, which looks less hacky than 'none', though still a hack. id must be the same as execution you want to override. If you don't specify id for execution, Maven will do it implicitly (in a way not expected intuitively by you).

After posting found it is already in stackoverflow: In a Maven multi-module project, how can I disable a plugin in one child?


For the record: the default execution IDs follow simple rules that are laid out in this answer: stackoverflow.com/a/34599117/7641
It is worth noting that this solution actually disables (as OP asked for) the plugin (for the given execution ID) instead of relying on a plugin-specific "skip" option.
L
Liviu Ilea

I know this thread is really old but the solution from @Ivan Bondarenko helped me in my situation.

I had the following in my 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>

What I wanted, was to disable the execution of generate-citrus-war for a specific profile and this was the solution:

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