195

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.

DennisLi
  • 3,915
  • 6
  • 30
  • 66
tobiasbayer
  • 10,269
  • 4
  • 46
  • 64

4 Answers4

257

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.

Alex
  • 8,093
  • 6
  • 49
  • 79
  • 13
    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. – Marcel Stör Jan 09 '13 at 08:06
  • 2
    For me in Maven 3 this doesn't work. true like bmargulies suggested works – mibutec Mar 19 '15 at 06:18
  • 10
    I had to add the `` part of the parent POM, then it worked for me. – mirabilos Nov 13 '15 at 15:59
  • 4
    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. – Zero3 Jan 09 '16 at 01:44
  • How have the enforcer plugin and it's finding duplicates in my test dependencies; which I don't care about. How can I tell it to not run on anything that's a test dependency – Christian Bongiorno Mar 18 '16 at 22:18
  • 13
    mirabilos's comment is the correct solution for Maven 3 and is portable across all plugins. Not all plugins have a `` parameter. – Gili Dec 17 '16 at 05:40
76

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>
bmargulies
  • 97,814
  • 39
  • 186
  • 310
  • How about naming the plugin you are working with, and running help:effective-pom to see if you really have the execution correct. – bmargulies Oct 19 '11 at 12:54
  • 1
    Also look out for plugins versus pluginManagement. The later overrides the former. – bmargulies Oct 19 '11 at 12:55
  • I am using the Cobertura plugin and I do not want to run it in the child pom. – tobiasbayer Oct 19 '11 at 13:11
  • The check goal has a skip in 2.5. It didn't before. The cobertura goal does not. – bmargulies Oct 19 '11 at 13:12
  • I don't want to skip just the check but the whole plugin execution. – tobiasbayer Oct 19 '11 at 13:23
  • let us [continue this discussion in chat](http://chat.stackoverflow.com/rooms/4384/discussion-between-tob-and-bmargulies) – tobiasbayer Oct 19 '11 at 13:24
  • No, let's move this to user@mojo.codehaus.org. There are more people there who can help and it's a better place to do tech support. – bmargulies Oct 19 '11 at 14:11
  • I also tried both options with `tomcat7-maven-plugin` but neither worked – amphibient Aug 22 '16 at 18:50
  • First option worked to disable the running of maven-dependency-plugin that was in the parent pom. Using maven 3.5.2 + java 8 – user674669 Apr 26 '18 at 04:15
  • 1
    Important note for those, who use **Tiles Maven Plugin** and considering to use second option (override execution by ID): the plugin [changes execution IDs](https://github.com/repaint-io/maven-tiles#execution-ids) inside the tile to reflect tile GAV coordinates. So in order for override to work `` tag should be added to the execution to preserve specified execution ID. – Ilya Serbis Feb 21 '21 at 14:24
  • Using skip=true doesn't work for me. I want to disable "checkstyle" plugin in "io.confluent:common" but your solution doesn't work for me. – emeraldhieu Jan 29 '23 at 09:49
40

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:

  1. phase is set to nothing, which looks less hacky than 'none', though still a hack.
  2. 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?

Alex
  • 8,093
  • 6
  • 49
  • 79
Ivan Bondarenko
  • 545
  • 5
  • 4
  • 2
    For the record: the default execution IDs follow simple rules that are laid out in this answer: http://stackoverflow.com/a/34599117/7641 – Jens Bannmann Jan 05 '16 at 12:38
  • 3
    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. – Zero3 Jan 09 '16 at 04:33
3

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>
Liviu Ilea
  • 1,494
  • 12
  • 13