Fulfilling the goal of the Maven plugin in the parent module, but not for children

We have a multi-module maven project that uses a profile that defines buildnumber-maven-plugin to increase the build number and then check it for source.

If I define the plugin in the parent pom.xml, it also performs all the child assemblies.

Here is my parent pom.xml

<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/maven-v4_0_0.xsd"> <modelVersion>4.0.0</modelVersion> <groupId>com.webwars</groupId> <artifactId>parent</artifactId> <packaging>pom</packaging> <properties> <buildNumber.properties>${basedir}/../parent/buildNumber.properties</buildNumber.properties> </properties> <version>1.0-SNAPSHOT</version> <name>Parent Project</name> <profiles> <profile> <id>release</id> <build> <plugins> <plugin> <groupId>org.apache.maven.plugins</groupId> <artifactId>maven-compiler-plugin</artifactId> <configuration> <debug>false</debug> <optimize>true</optimize> </configuration> </plugin> <plugin> <groupId>org.codehaus.mojo</groupId> <artifactId>buildnumber-maven-plugin</artifactId> <version>1.0-beta-3</version> <executions> <execution> <phase>validate</phase> <goals> <goal>create</goal> </goals> </execution> </executions> <configuration> <buildNumberPropertiesFileLocation>${buildNumber.properties}</buildNumberPropertiesFileLocation> <getRevisionOnlyOnce>true</getRevisionOnlyOnce> <doCheck>false</doCheck> <doUpdate>false</doUpdate> <format>{0, number}</format> <items> <item>buildNumber</item> </items> </configuration> </plugin> <plugin> <groupId>org.apache.maven.plugins</groupId> <artifactId>maven-scm-plugin</artifactId> <executions> <execution> <phase>install</phase> <goals> <goal>checkin</goal> </goals> </execution> </executions> <configuration> <basedir>${basedir}</basedir> <includes>buildNumber.properties</includes> <message>[Automated checkin] of ${basedir} Build version: ${major.version}.${minor.version}.${buildNumber}</message> <developerConnectionUrl>...</developerConnectionUrl> </configuration> </plugin> </plugins> </build> </profile> </profiles> <modules> <module>../common</module> <module>../data</module> <module>../client</module> <module>../webplatform</module> </modules> ... </project> 
+46
version-control maven-2 build-process versioning
Nov 03 '09 at 23:48
source share
5 answers

As described in the plugins pom help section:

In addition to the standard coordinate of groupId: artifactId: version, there are elements that configure the plugin or this creates an interaction with it.

  • inherited: true or false whether this plugin configuration should apply to POMs that inherit from it.

So just add <inherited>false</inherited> to the buildnumber-maven-plugin configuration to avoid inheritance in child POMs:

  <plugin> <groupId>org.codehaus.mojo</groupId> <artifactId>buildnumber-maven-plugin</artifactId> <version>1.0-beta-3</version> <inherited>false</inherited> ... </plugin> 
+76
Nov 04 '09 at 1:14
source share

You can add <inherited>false</inherited> to the plugin configuration to avoid inheritance in child POMs:

  <plugin> <groupId>org.codehaus.mojo</groupId> <artifactId>buildnumber-maven-plugin</artifactId> <version>1.0-beta-3</version> <inherited>false</inherited> ... </plugin> 

Or, if your plugin has several executions, you can control which executions are inherited and which are not by adding an inherited tag to the execution body:

 <plugin> <groupId>org.apache.maven.plugins</groupId> <artifactId>maven-antrun-plugin</artifactId> <executions> <execution> <id>parent-only</id> <phase>initialize</phase> <inherited>false</inherited> <configuration> <target> <echo message="Echoed only by this module."/> </target> </configuration> <goals> <goal>run</goal> </goals> </execution> <execution> <id>all-modules</id> <phase>initialize</phase> <inherited>true</inherited> <!-- Defaults to true, so you could leave this line out --> <configuration> <target> <echo message="Echoed in this module and each child module."/> </target> </configuration> <goals> <goal>run</goal> </goals> </execution> </executions> </plugin> 
+21
Sep 19 '11 at 19:21
source share

Just adding to the great answers here: note that execution inheritance is broken in Maven 2: http://jira.codehaus.org/browse/MNG-3959

+3
Feb 09 '13 at 0:29
source share

There is a built-in maven option: mvn --help ... -N,--non-recursive Do not recurse into sub-projects

+3
Oct 12 '16 at 2:06
source share

If the plugin is regular and you have access to the MOJO code plugin, you can mark the plugin as aggregator ; if the expected behavior is applicable for all projects in which the plugin should be used.

As stated in the Mojo API Specification ,

Flags of this Mojo to launch it in several ways, i.e. aggregate build with a set of projects listed as modules.

Example,

 @Mojo(name = "createHF", inheritByDefault = false, aggregator = true) public class CreateHFMojo extends AbstractMojo { .. public void execute() throws MojoExecutionException, MojoFailureException { .... } .. } 

Detailed github example.

+1
Jun 15 '17 at 15:51
source share



All Articles