views:

731

answers:

1

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"&gt;
  <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>
+4  A: 

As documented in the Plugins section of the pom reference:

Beyond the standard coordinate of groupId:artifactId:version, there are elements which configure the plugin or this builds interaction with it.

  • inherited: true or false, whether or not this plugin configuration should apply to POMs which inherit from this one.

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

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