在父模块上执行 Maven 插件目标,但不在子模块上执行 [英] Execute Maven plugin goal on parent module, but not on children

查看:30
本文介绍了在父模块上执行 Maven 插件目标,但不在子模块上执行的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我们有一个多模块 maven 项目,该项目使用定义了 buildnumber-maven-插件以增加内部版本号,然后将其签入源代码管理.

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.

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

If I define the plugin in the parent pom.xml it executes for all the child builds as well.

这是我的父 pom.xml

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>

推荐答案

插件<中所述pom 参考的/a> 部分:

As documented in the Plugins section of the pom reference:

除了 groupId:artifactId:version 的标准坐标之外,还有一些元素可以配置插件或构建与其交互的元素.

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

  • inherited:true 或 false,无论此插件配置是否应应用于从该插件继承的 POM.
  • inherited: true or false, whether or not this plugin configuration should apply to POMs which inherit from this one.

因此只需将 false 添加到 buildnumber-maven-plugin 配置中,以避免子 POM 中的继承:

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>

这篇关于在父模块上执行 Maven 插件目标,但不在子模块上执行的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆