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.

Leave a Comment