In a Maven multi-module project, how can I disable a plugin in one child?

By "run the plugin", I'm assuming you mean that the plugin is bound to a lifecycle phase, and you'd like to unbind it in some modules. First, you could consider changing your POM inheritance so that the modules that don't need the plugins have one parent and the ones that do have a different parent. If you don't want to do that, then you can explicitly set the execution phase to "nothing" in a child module. E.g. if you had a parent pom configuration like this:

<plugin>
    <groupId>org.codehaus.mojo</groupId>
    <artifactId>exec-maven-plugin</artifactId>
    <version>1.2.1</version>
    <executions>
        <execution>
            <id>i-do-something</id>
            <phase>initialize</phase>
            <goals>
                <goal>exec</goal>
            </goals>
            <configuration>
                ... lots of configuration
            </configuration>
        </execution>
    </executions>
</plugin>

Then in a child module, you could do this:

<plugin>
    <groupId>org.codehaus.mojo</groupId>
    <artifactId>exec-maven-plugin</artifactId>
    <version>1.2.1</version>
    <executions>
        <execution>
            <id>i-do-something</id>
            <phase/>
        </execution>
    </executions>
</plugin>

Because it's the same plugin and the same execution id, it overrides the configuration specified in the parent, and now the plugin isn't bound to a phase in the child project.


Ryan Stewart's answer works if execution that you wish to suppress in the parent pom is tagged with an id. If, however, the parent pom doesn't tag the execution with an id (and, of course, you can't edit that parent pom) then I found that doing the following suppresses the parent pom's action.

  1. First set the phase of the execution to none
  2. Create another execution, give it an id and do in it what you need it to do.
  3. run mvn help:effective-pom to confirm that it has correctly suppressed what you needed suppressed from the parent pom.

Here's an example: This is how my parent pom looked like:

    <plugin>
      <artifactId>maven-source-plugin</artifactId>
      <version>2.1.2</version>
      <executions>
        <execution>
          <phase>package</phase>
          <goals>
            <goal>jar</goal>
          </goals>
        </execution>
      </executions>
      <inherited>true</inherited>
    </plugin>

I needed to change the goal to jar-no-fork. Note that the execution in parent pom doesn't have an id that I could use to disable it. So here's what added to my child pom:

            <plugin>
                <groupId>org.apache.maven.plugins</groupId>
                <artifactId>maven-source-plugin</artifactId>
                <executions>
                    <execution>
                        <phase>none</phase>
                    </execution>
                    <execution>
                        <id>attach-sources</id>
                        <goals>
                            <goal>jar-no-fork</goal>
                        </goals>
                    </execution>
                </executions>
            </plugin>

As a result this is how the effective-pom looks like:

      <plugin>
        <artifactId>maven-source-plugin</artifactId>
        <version>2.2.1</version>
        <executions>
          <execution>
            <phase>none</phase>
            <goals>
              <goal>jar</goal>
            </goals>
            <configuration>
              <archive>
                <compress>false</compress>
              </archive>
            </configuration>
          </execution>
          <execution>
            <id>attach-sources</id>
            <goals>
              <goal>jar-no-fork</goal>
            </goals>
            <configuration>
              <archive>
                <compress>false</compress>
              </archive>
            </configuration>
          </execution>
        </executions>
        <inherited>true</inherited>
        <configuration>
          <archive>
            <compress>false</compress>
          </archive>
        </configuration>
      </plugin>

This ensured that the goal jar never runs and only the goal jar-no-fork executes -- which is what I wanted to achieve.