简体   繁体   English

在聚合根不是父pom的多模块Maven项目中更新模块的版本号

[英]Updating version numbers of modules in a multi-module Maven project where the aggregate root isn't a parent pom

I want to set a release version for my project. 我想为我的项目设置发行版本。 I use an aggregate pom for all modules. 我对所有模块都使用了聚合pom。 Each module parent is not the aggregate pom mentioned before. 每个模块父级都不是前面提到的聚合pom。

My question differs from Updating version numbers of modules in a multi-module Maven project question, there the aggregate pom is a parent pom as well. 我的问题与在多模块Maven项目问题中更新模块的版本号不同,那里的聚合pom也是父pom。

The aggregate pom.xml is: 聚合pom.xml为:

<?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/xsd/maven-4.0.0.xsd">
    <modelVersion>4.0.0</modelVersion>

    <groupId>com.example</groupId>
    <artifactId>aggregate</artifactId>
    <version>0.0.1</version>
    <packaging>pom</packaging>

    <modules>
        <module>module1</module>
    </modules>

</project>

Where the module1 pom.xml is: 其中module1 pom.xml是:

<?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/xsd/maven-4.0.0.xsd">
    <modelVersion>4.0.0</modelVersion>

    <groupId>com.example</groupId>
    <artifactId>module-1</artifactId>
    <version>1.0-SNAPSHOT</version>

    <parent>
        <groupId>com.example</groupId>
        <artifactId>parent1</artifactId>
        <version>1.0-SNAPSHOT</version>
        <relativePath>../../parent1/pom.xml</relativePath>
    </parent>

</project>

When I execute: 当我执行时:

mvn versions:set -DnewVersion=0.0.1

[INFO] Scanning for projects...
[INFO] ------------------------------------------------------------------------
[INFO] Reactor Build Order:
[INFO]
[INFO] module-1
[INFO] aggregate
[INFO]
[INFO] ------------------------------------------------------------------------
[INFO] Building aggregate 0.0.1
[INFO] ------------------------------------------------------------------------
[INFO]
[INFO] --- versions-maven-plugin:2.3:set (default-cli) @ aggregate ---
[INFO] Searching for local aggregator root...
[INFO] Local aggregation root: C:\Users\maxim.kirilov\workspace\maven-games\aggregate
[INFO] Processing change of com.example:aggregate:0.0.1 -> 0.0.1
[INFO] ------------------------------------------------------------------------
[INFO] Reactor Summary:
[INFO]
[INFO] module-1 ........................................... SKIPPED
[INFO] aggregate .......................................... SUCCESS [  0.962 s]
[INFO] ------------------------------------------------------------------------
[INFO] BUILD SUCCESS

Why module-1 is skipped? 为什么跳过模块1? I read some articles that suggests to invoke the maven set version command for each module separately, does maven support for cleaner solution? 我读过一些文章建议对每个模块分别调用maven set version命令,maven是否支持更干净的解决方案?

Recently (23/09/2017) a documentation was added to Versions Maven Plugin. 最近(2017年9月23日),文档已添加到Versions Maven插件。 In order to update all project under aggregate project you need to add supplemental command line parameters: 为了更新聚合项目下的所有项目,您需要添加补充命令行参数:

mvn versions:set -DnewVersion=0.0.1 -DoldVersion=* -DgroupId=* -DartifactId=*

This is needed otherwise the filter for the versions (via -DoldVersion= ) would have filtered out that module cause it has a different version than the rest of modules. 这是必需的,否则版本的过滤器(通过-DoldVersion = )将过滤掉该模块,因为它的版本与其余模块的版本不同。 Furthermore you need to add the -DgroupId= and -DartifactId=* otherwise the module-1 will also filtered out based on the differences in groupId and artifactId. 此外,您需要添加-DgroupId =和-DartifactId = *,否则module-1还将根据groupId和artifactId的差异而被过滤掉。

You may need to include Versions Maven Plugin in your aggregate pom xml. 您可能需要在聚合pom xml中包括Versions Maven插件。 http://www.mojohaus.org/versions-maven-plugin/ http://www.mojohaus.org/versions-maven-plugin/usage.html http://www.mojohaus.org/versions-maven-plugin/ http://www.mojohaus.org/versions-maven-plugin/usage.html

something like this i do: 我做这样的事情:

 <plugins>
    <plugin>
      <groupId>org.codehaus.mojo</groupId>
      <artifactId>versions-maven-plugin</artifactId>
      <version>2.3</version>
      <configuration>
     <autoVersionSubmodules>true</autoVersionSubmodules>
     </configuration>
    </plugin>
 </plugins>

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM