31

I have a parent pom with a few plugins. In my child pom, I want to exclude one plugin.

How can I do this?

juan
  • 80,295
  • 52
  • 162
  • 195
user373201
  • 10,945
  • 34
  • 112
  • 168

4 Answers4

14

I had a similar requirement to run some plugins in the child but not the parent POM. i achieved this by stating <skip>true</skip> in the parent POM.

the parent pom entry is below

<plugin>
        <groupId>eviware</groupId>
        <artifactId>maven-soapui-plugin</artifactId>
        <version>4.0.0</version>
        <inherited>false</inherited>
        <dependencies>
          <dependency>
            <groupId>junit</groupId>
            <artifactId>junit</artifactId>
            <version>4.8.2</version>
          </dependency>
        </dependencies> 
        <configuration>
          <skip>true</skip>
        </configuration>
      </plugin> 

The child project pom entry is below

<plugins>
        <plugin>
            <groupId>eviware</groupId>
            <artifactId>maven-soapui-plugin</artifactId>
            <version>4.0.0</version>
            <configuration>
                <settingsFile>site-service-web/src/test/soapui/soapui-settings.xml</settingsFile>
                <projectFile>site-service-web/src/test/soapui/PodifiSite-soapui-project.xml</projectFile>
                <outputFolder>site-service-web/target/surefire-reports</outputFolder>
                <junitReport>true</junitReport>
                <exportwAll>true</exportwAll>
                <printReport>true</printReport>
            </configuration>
        </plugin>
    </plugins>
messivanio
  • 2,263
  • 18
  • 24
Rafeeq
  • 259
  • 3
  • 3
7

You can define all plugins in parent pom in pluginManagement section

    <pluginManagement>
            <plugins>
                ...
                 <plugin>
                    <artifactId>maven-dependency-plugin</artifactId>
                    <version>2.8</version>
                    <executions>
                        <execution>
                            <id>unpack-dependencies</id>
                            <phase>generate-sources</phase>
                            <goals>
                                <goal>unpack-dependencies</goal>
                            </goals>
                            <configuration>
                                <includeTypes>tar.bz2</includeTypes>
                                <outputDirectory>${project.basedir}/target/dependencies</outputDirectory>
                            </configuration>
                        </execution>
                    </executions>
                </plugin>
              ...
            </plugins>
</pluginManagement>

And after in parent and child poms you can control the execution phase of this plugin

<plugins>
      <plugin>
            <artifactId>maven-dependency-plugin</artifactId>
            <inherited>false</inherited>
            <executions>
                <execution>
                    <id>unpack-dependencies</id>
                    <phase>none</phase>
                </execution>
            </executions>
        </plugin>
  </plugins>

If you paste this in parent pom do not forget option <inherited>false</inherited>, its disable execution inheritance in child pom.

Doroshenko
  • 111
  • 1
  • 3
  • This works like a charm and even has the advantage that the plugin is never executed in the first place. Using `ignore` will actually still call into the plugin, but let the plugin decide. Using `phase=none` prevent Maven from even lookup up the plugin's classpath, which can be helpful in some scenarios. – ctron May 09 '17 at 08:31
3

You can declare all the plugins in your parent pom within <pluginManagement>. In each child, you can declare the plugins which are used by that child. This way, you can include or exclude plugins as appropriate.

You can look at this related SO discussion as well.

Community
  • 1
  • 1
Raghuram
  • 51,854
  • 11
  • 110
  • 122
  • 3
    In my case I have a plugin that is used by 9 out of 10 sub modules. I thought it would be easier to put the plugin in parent and let the 9 children inherit and tell the 10th one to exclude. I know the way you are talking about. Just wondering if its possible to just exclude a plugin from a child project....If maven doesn't have that ability, that is fine. I don't know maven all together, so posted here to find out if maven has that sort of a feature. – user373201 Jan 31 '11 at 12:51
  • 15
    This answer does not really answer the question of how to exclude some particular inherited plugin. – Pablo Lalloni Feb 20 '14 at 18:05
1

You could use a profile activated by a property to determine whether the plugin is used or not. By default the property could be activated and the one project you do not want to use it in could include the property value to exclude the plugin.

Brett Okken
  • 6,210
  • 1
  • 19
  • 25