We have a multi-module maven project that uses a profile that defines a buildnumber-maven-plugin to increment a build number and then check it into source control.
If I define the plugin in the parent pom.xml it executes for all the child builds as well.
Here's 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>
See Question&Answers more detail:
os 与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…