In a Maven project, how can I automatically update the version all child modules, plus the parent?
I have a multi-module project.
parent POM (1.0-SNAPSHOT) |-- module1 (1.0-SNAPSHOT) |-- module2 (1.0-SNAPSHOT) `-- module3 (1.0-SNAPSHOT)
When I execute m开发者_开发知识库vn release:prepare it verify that parent POM has a SNAPSHOT version and all dependent modules don't have a SNAPSHOT version. How automatically update all child modules from SNAPSHOT to the next release version?
I would like automatically increment version for all modules.
A flexible way to set poms versions, multi-modules projects included, is Versions Maven Plugin.
mvn versions:set -DnewVersion=your_new_version
It will adjust all pom versions, parent versions and children versions in a multi-module project.
then
mvn versions:commit
or
mvn versions:revert
The release plugin can handle that. Did you check Updating POM Versions? But...
I don't get something. Changing the version in the POMs from x-SNAPSHOT to a new version and bumping the version in the POMs to a new value y-SNAPSHOT should be done by release:prepare
as explained in Prepare a Release. What is going wrong when using this goal?
Update: The autoVersionSubmodules
parameter might be what you're looking for. From the Prepare a Release example:
Multi-module projects
You will be prompted for the version number for each module of the project. If you prefer that every module gets the same version as the parent POM, you can set the option
autoVersionSubmodules
totrue
. Now you will be asked only once for the release version and the next development version.
Snippet of parent pom.xml
<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>
- Make the version of all sub-project be defined in its parent pom.xml.
Make 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
There is a potentially better option over at https://issues.apache.org/jira/browse/MNG-624?focusedCommentId=14415968&page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel#comment-14415968
That is a workaround for the fact that you can't refer to the top level pom in the sub-module poms without having an explicit version listed. (which is what bug MNG-624 is about) It explains how you can have a single location for the version (in a top-level profiles.xml file), and simply have a property references in all the pom.xml files (i.e. ${currentVersion})
However, in this scheme release:prepare probably won't update profiles.xml for you.
精彩评论