Version control 在父模块上执行Maven插件目标,但不在子模块上执行
我们有一个多模块maven项目,它使用一个概要文件,该概要文件定义了一个增量版本号,然后将其签入源代码管理 如果我在父pom.xml中定义插件,它也会对所有子构建执行 这是我的父母pom.xmlVersion control 在父模块上执行Maven插件目标,但不在子模块上执行,version-control,maven-2,build-process,versioning,Version Control,Maven 2,Build Process,Versioning,我们有一个多模块maven项目,它使用一个概要文件,该概要文件定义了一个增量版本号,然后将其签入源代码管理 如果我在父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/
<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>
4.0.0
com.webwars
父母亲
聚甲醛
${basedir}/./parent/buildNumber.properties
1.0-快照
父项目
释放
org.apache.maven.plugins
maven编译器插件
假的
真的
org.codehaus.mojo
buildnumber maven插件
1.0-beta-3
验证
创造
${buildNumber.properties}
真的
假的
假的
{0,数字}
建筑编号
org.apache.maven.plugins
maven scm插件
安装
签到
${basedir}
buildNumber.properties
${basedir}生成版本的[自动签入]:${major.version}.${minor.version}.${buildNumber}
...
../普通
../数据
../client
../webplatform
...
如pom参考部分所述:
除了groupId:artifactId:version的标准坐标之外,还有一些元素配置插件或构建与插件的交互
- 继承:true或false,该插件配置是否应应用于从该配置继承的POM
false
添加到buildnumber maven插件配置中,以避免子POM中的继承:
<plugin>
<groupId>org.codehaus.mojo</groupId>
<artifactId>buildnumber-maven-plugin</artifactId>
<version>1.0-beta-3</version>
<inherited>false</inherited>
...
</plugin>
<plugin>
<groupId>org.codehaus.mojo</groupId>
<artifactId>buildnumber-maven-plugin</artifactId>
<version>1.0-beta-3</version>
<inherited>false</inherited>
...
</plugin>
org.codehaus.mojo
buildnumber maven插件
1.0-beta-3
假的
...
您可以将false
添加到插件配置中,以避免子POM中的继承:
<plugin>
<groupId>org.codehaus.mojo</groupId>
<artifactId>buildnumber-maven-plugin</artifactId>
<version>1.0-beta-3</version>
<inherited>false</inherited>
...
</plugin>
<plugin>
<groupId>org.codehaus.mojo</groupId>
<artifactId>buildnumber-maven-plugin</artifactId>
<version>1.0-beta-3</version>
<inherited>false</inherited>
...
</plugin>
org.codehaus.mojo
buildnumber maven插件
1.0-beta-3
假的
...
或者,如果您的插件有多个执行,您可以通过向执行体添加继承的标记来控制哪些执行是继承的,哪些不是继承的:
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-antrun-plugin</artifactId>
<executions>
<execution>
<id>parent-only</id>
<phase>initialize</phase>
<inherited>false</inherited>
<configuration>
<target>
<echo message="Echoed only by this module."/>
</target>
</configuration>
<goals>
<goal>run</goal>
</goals>
</execution>
<execution>
<id>all-modules</id>
<phase>initialize</phase>
<inherited>true</inherited> <!-- Defaults to true, so you could leave this line out -->
<configuration>
<target>
<echo message="Echoed in this module and each child module."/>
</target>
</configuration>
<goals>
<goal>run</goal>
</goals>
</execution>
</executions>
</plugin>
org.apache.maven.plugins
maven antrun插件
仅限家长
初始化
假的
跑
所有模块
初始化
真的
跑
这只是对这里伟大答案的补充:注意,每次执行继承在Maven 2中被破坏:有一个内置的Maven选项:
mvn—帮助
...
-N、 --非递归不递归到子项目中
如果该插件是自定义插件,并且您可以访问插件MOJO代码,则可以将该插件标记为聚合器;如果预期行为适用于将使用插件的所有项目
如中所述
将此Mojo标记为以多模块方式运行,即聚合
使用列为模块的项目集进行构建
例如
@Mojo(name = "createHF", inheritByDefault = false, aggregator = true)
public class CreateHFMojo extends AbstractMojo {
..
public void execute() throws MojoExecutionException, MojoFailureException {
....
}
..
}
关于的详细示例