turn off buildnumber-maven-plugin for submodules

2019-08-11 10:11发布

问题:

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?

回答1:

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>


回答2:

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.



回答3:

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