16

In parent POM, I have:

 <pluginManagement>
            <plugin>
                <artifactId>maven-resources-plugin</artifactId>
                <version>2.5</version>
                <executions>
                    <execution>
                       <id>execution 1</id>
                       ...
                    </execution>
                    <execution>
                       <id>execution 2</id>
                       ...
                    </execution>
                    <execution>
                       <id>execution 3</id>
                       ...
                    </execution>
                </executions>
            </plugin>
        <pluginManagement>

My questions are:

  1. Is it possible to disable some <execution> in sub-projects, e.g, only run execution 3 and skip 1 and 2?
  2. Is it possible to totally override the executions in sub-projects, e.g. I have an exection 4 in my sub-projects and I want only run this execution and never run execution 1,2,3 in parent POM.
Mike
  • 3,515
  • 10
  • 44
  • 67
  • 1
    The proposed recommended solution using per-project POM properties for profile activation won't work because only global system properties can be used for this. – Bernhard Stadler Oct 13 '16 at 07:56

1 Answers1

25

A quick option is to use <phase>none</phase> when overriding each execution. So for example to run execution 3 only you would do the following in your pom:

<build>
  <plugins>
    <plugin>
        <artifactId>maven-resources-plugin</artifactId>
        <version>2.5</version>
        <executions>
            <execution>
                <id>execution 1</id>
                <phase>none</phase>
                ...
            </execution>
            <execution>
                <id>execution 2</id>
                <phase>none</phase>
                ...
            </execution>
            <execution>
                <id>execution 3</id>
                ...
            </execution>
        </executions>
    </plugin>
    ...
  </plugins>
  ...
</build>

It should be noted that this is not an officially documented feature, so support for this could be removed at any time.

The recommend solution would probably be to define profiles which have activation sections defined:

<profile>
  <id>execution3</id>
  <activation>
    <property>
      <name>maven.resources.plugin.execution3</name>
      <value>true</value>
    </property>
  </activation>
  ...

The in your sub project you would just set the required properties:

<properties>
    <maven.resources.plugin.execution3>true</maven.resources.plugin.execution3>
</properties>

More details on profile activation can be found here: http://maven.apache.org/settings.html#Activation

DB5
  • 13,553
  • 7
  • 66
  • 71
  • While I agree that you should be using profiles for these, main problem here is poorly defined parent poms (that you cannot modify) that leak their configurations. – Dragas Mar 29 '23 at 11:35