If you want to have a profile that should be applied to submodules (and only some of them), defined centrally in their parent project (pom) and not apply the profile to the parent itself, here is the proposed approach:
Define the profile in the parent pom, pattern one:
<profiles> <profile> <id>sample-profile</id> <build> <plugins> <plugin> <groupId>org.apache.maven.plugins</groupId> <artifactId>maven-antrun-plugin</artifactId> <version>1.5</version> <executions> <execution> <id>print-hello</id> <phase>${phase.prop}</phase> <goals> <goal>run</goal> </goals> <configuration> <target> <echo message="hello there!" /> </target> </configuration> </execution> </executions> </plugin> </plugins> </build> </profile> </profiles>
Please note that we do:
- the plugin
phase parameter is parameterized, therefore the binding of the plugin to the assembly phase will also be parameterized - Now we can decide through the property to which the phase attaches this plugin execution.
- Now we can decide through the property to attach this plugin execution to the phase (or empty phase)
So, in the same parent pom, define a property:
<properties> <phase.prop>none</phase.prop> </properties>
Thus, the assembly performed on the parent pom will attach the execution of the plugin to the phase ( none is a keyword or a symbolic value, but simply the de facto standard used for a nonexistent phase, you can leave it empty or put any value that you like, it will have the same effect) and therefore skip it. It will also be skipped by default in all declared modules. The profile will still be active in each module, but will be harmless, because by default it will not execute any plug-in.
Then in the modules in which you want the actions of the plugin to be active, you could only override the corresponding property and the necessary phase:
<properties> <phase.prop>package</phase.prop> </properties>
If you then activate the profile from the main assembly (parent)
mvn clean install -Psample-profile
The parent will apply it to all modules, but the effective execution of the effect will occur only where the value of phase.prop has the significant maven value.
If you need different phases for different plugins, you can define more than one property and apply the same template.
If you do not have a plugin, but rather the global plugin configuration for a plugin already executed by Maven (as part of its default packaging and assembly), you could then override its execution by overriding the default execution identifier .
Note that we could do the same with the skip configuration element, but:
- not all plugins provide a
skip configuration entry - using the
phase element is not related to any configuration and can be reused for execution connected to the same phase