本文介绍了在父模块而不是子模块上执行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>
推荐答案
As documented in the Plugins section of the pom reference:
- 继承:是或否,无论此插件配置是否适用于从此插件继承的POM.
- 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中继承:
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插件目标的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!