version-control - 在父模块上执行 Maven 插件目标,但不在子模块上执行

标签 version-control maven-2 build-process versioning

我们有一个多模块 Maven 项目,它使用定义 buildnumber-maven-plugin 的配置文件。增加内部版本号,然后将其 checkin 源代码管理。

如果我在父 pom.xml 中定义插件,它也会为所有子构建执行。

这是我的父 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>

最佳答案

Plugins 中所述pom 引用部分:

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.

所以只需添加 <inherited>false</inherited>到 buildnumber-maven-plugin 配置以避免在子 POM 中继承:

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

关于version-control - 在父模块上执行 Maven 插件目标,但不在子模块上执行,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/1670900/

相关文章:

git - git 命令 - checkout 和 switch 之间的区别

build-process - 在自动构建中生成文档

c++ - header 导入并包含 XCode、cmath、objc-class.h 等中的失败

perl - Electric commander 和教程中的说明

asp.net - 寻找好的Web应用程序部署策略(ASP.NET MVC3)

git - git pull 和 git reset --hard origin/<branch> 有什么区别?

java - Resin 的 `pomegranate' - 自动神奇加载项目的 Maven jar 依赖项 - 但如何使用 pom.xml 为它们生成 jar?

java - 如何使用 Maven 的程序集插件将 Implementation-Version 值添加到 jar list ?

maven-2 - 项目组织有效

svn - SVN:如何比较工作副本和版本库?