1

Parent:

    <plugins>
        <plugin>
            <groupId>org.codehaus.mojo</groupId>
            <artifactId>buildnumber-maven-plugin</artifactId>
            <version>1.0</version>
            <executions>
                <execution>
                    **<inherited>false</inherited>**
                    <goals>
                        <goal>create</goal>
                    </goals>
                </execution>
            </executions>
            <configuration>
                <format>${project.version}-b{0,number}</format>
                <items>
                    <item>buildNumber0</item>
                </items>
                <doCheck>false</doCheck>
                <doUpdate>false</doUpdate>
            </configuration>
        </plugin>
    </plugins>

<modules>
    <module>module1</module>
    <module>module2</module>
</modules>

During 'mvn buildnumber:create' each module generate buildnumber. Is it possible to turn it off for submodules? In other word, during 'mvn buildnumber:create' build number should be generated only once in parent module.

I tryed set <phase>none</phase> and <skip>true</skip> in submodules but without any changes.

Suggestions?

Jean-Rémy Revy
  • 5,607
  • 3
  • 39
  • 65
Alex
  • 967
  • 4
  • 15
  • 38
  • For your multi-module project, are you using it to eventually build up a single artifact (like a war or ear)? If so, you could just use the buildnumber plugin for that single module instead of at the root. – Michael Feb 01 '12 at 22:24
  • @Michael I could, but anyway buildnumber plugin executes for all modules. What I did wrong? – Alex Feb 02 '12 at 08:57
  • you didn't do anything wrong. You specified a build directive in your root pom, which in a multi-module pom flows downward. Your child modules use your parent pom as parent which means they do everything in there also. So your code is doing exactly what you asked it to. – Michael Feb 02 '12 at 17:55

3 Answers3

3

This: Execute Maven plugin goal on parent module, but not on children

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

  <plugin>
    <groupId>org.codehaus.mojo</groupId>
    <artifactId>buildnumber-maven-plugin</artifactId>
    <version>1.0</version>
    <inherited>false</inherited>
    ...
  </plugin>
Community
  • 1
  • 1
tveon
  • 579
  • 5
  • 24
1

I would take a look into the:

<pluginManagement>...</pluginManagement>

element: http://maven.apache.org/pom.html#Plugin_Management

I've had success defining my plugins in my master/parent/root pom file through the plugin-management section, and then simply enabling their behaviour in my child pom files by simply specifying the group/artifact combination.

In your case, I'd try the following...

In your root pom.xml (notice the <pluginManagement> element):

...
<build>
  ...
  <pluginManagement>
    <plugins>
      <plugin>
        <groupId>org.codehaus.mojo</groupId>
        <artifactId>buildnumber-maven-plugin</artifactId>
        <version>1.0</version>
        <executions>
            <execution>
                <goals>
                    <goal>create</goal>
                </goals>
            </execution>
        </executions>
        <configuration>
            <format>${project.version}-b{0,number}</format>
            <items>
                <item>buildNumber0</item>
            </items>
            <doCheck>false</doCheck>
            <doUpdate>false</doUpdate>
        </configuration>
      </plugin>
    </plugins>
  </pluginManagement>
...
</build>
...

And then simply enable the behaviour in your module1 (or module2) pom.xml by (NO <pluginManagement> element):

<build>
  ...
  <plugins>
    <plugin>
      <groupId>org.codehaus.mojo</groupId>
      <artifactId>buildnumber-maven-plugin</artifactId>
    <plugin>
  <plugins>
  ...
</build>
...

This was all from memory, give it a shot and if it doesn't work, let me know.

Dan
  • 1,955
  • 17
  • 21
-1

Update your pom to use version 1.3 of the plugin, then configure the plugin in each sub module with true

roostergx
  • 3,510
  • 1
  • 15
  • 5