父POM (1.0-SNAPSHOT) |-- 模块1 (1.0-SNAPSHOT) |-- 模块2 (1.0-SNAPSHOT) `-- 模块3 (1.0-SNAPSHOT)
当我执行 mvn release:prepare 时,它会验证父POM是否具有SNAPSHOT版本以及所有依赖模块是否没有SNAPSHOT版本。如何自动更新所有子模块从SNAPSHOT版本到下一个发布版本?
我希望能够自动递增所有模块的版本号。
一个灵活的方式来设置POM文件版本,包括多模块项目,就是使用Versions Maven Plugin插件。
mvn versions:set -DnewVersion=your_new_version
它将调整多模块项目中的所有pom版本、父版本和子版本。
然后
mvn versions:commit
或者mvn versions:revert
commit
和 revert
操作针对 set
命令期间创建的备份 POM 文件,但在我使用版本控制并可以简单地还原到 git 中的内容时,我认为这是不必要的。通过在 set
命令中添加 -DgenerateBackupPoms=false
,之后就不需要 commit
或 set
了。这是我的想法。 - Adamversions:deleteBackupPoms
和versions:revertToBackupPoms
。 - Adamrelease:prepare
完成,如准备发布中所述。当使用此目标时出现了什么问题?
更新:autoVersionSubmodules
参数可能是您要寻找的内容。从准备发布示例中可知:
您将被提示输入项目每个模块的版本号。如果您希望每个模块都获得与父POM相同的版本号,则可以将选项autoVersionSubmodules
设置为true
。现在,您只需要被问及一次关于发布版本和下一个开发版本。
<build>
<plugins>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-release-plugin</artifactId>
<version>x.y.z</version>
<configuration>
<goals>deploy</goals>
<autoversionsubmodules>true</autoversionsubmodules>
</configuration>
</plugin>
</plugins>
</build>
release:prepare
目标会为您完成此操作(请再次检查链接)。 - Pascal ThiventMake sure all sub-projects versions are the same to their parent's version.
<groupId>com.xyz</groupId>
<artifactId>module-1</artifactId>
<packaging>jar</packaging>
<parent>
<groupId>com.xyz</groupId>
<artifactId>xyz-parent</artifactId>
<version>1.0.123-SNAPSHOT</version>
</parent>
<?xml version="1.0" encoding="UTF-8"?>
<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>
<artifactId>xyz-parent</artifactId>
<groupId>com.xyz</groupId>
<version>1.0.123-SNAPSHOT</version>
<packaging>pom</packaging>
<name>xyz-parent</name>
<dependencyManagement>
<dependencies>
<!-- Message -->
<dependency>
<groupId>com.xyz</groupId>
<artifactId>module-1</artifactId>
<version>${project.version}</version>
</dependency>
<dependency>
<groupId>com.xyz</groupId>
<artifactId>module-2</artifactId>
<version>${project.version}</version>
</dependency>
</dependencyManagement>
</project>
Create another pom.xml to group those project together.
<modules>
<module>../xyz-parent</module>
<module>../module-1</module>
<module>../module-2</module>
</modules>
Then update the parent project's version and then build it by below command.
mvn versions:set -DnewVersion=1.0.1004-SNAPSHOT
mvn clean install
Then update the parent's version which is defined in those sub-project to the latset one
mvn -N versions:update-child-modules
Then build them together.
@echo on
cd .\xyz-parent
call mvn versions:set -DnewVersion=1.0.1004-SNAPSHOT -o
call mvn versions:commit -o
call mvn clean install -o
:::http://www.mojohaus.org/versions-maven-plugin/examples/update-child-modules.html
cd ..\xyz-buildaggregate-ide
call mvn -N versions:update-child-modules -o
call mvn clean install -o
这是解决无法在子模块pom中引用顶级pom而不需要列出显式版本的一种方法(这就是bug MNG-624的问题所在)。它解释了如何在顶层profiles.xml文件中拥有单个版本位置,并在所有pom.xml文件中简单地引用属性(即${currentVersion})。
但是,在这个方案中,release:prepare可能不会为您更新profiles.xml。