Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Is it possible to override executions in maven pluginManagement?

Tags:

maven

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.
like image 996
Mike Avatar asked Jul 03 '13 05:07

Mike


1 Answers

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

like image 194
DB5 Avatar answered Nov 16 '22 01:11

DB5