【问题标题】:How to update version on dependent sibling module with Versions Maven Plugin如何使用版本 Maven 插件更新依赖兄弟模块的版本
【发布时间】:2010-08-31 06:03:06
【问题描述】:

我在更新依赖同级项目的依赖版本时遇到问题。

我的简化项目设置如下。

root
|--parent
|--tool-core
|--tool
|--functional-tests

父项目拥有所有的全局属性和依赖管理。功能测试依赖于工具,而工具依赖于工具核心。根pom.xml 仅聚合(指定是否包含功能测试),并且父项目是所有项目的父项目。我不知道这是否是微不足道的,但父级不包含在聚合中,因为它已经是每个子项目的父级。

现在,我的问题是如果我用versions:set 更改工具的版本。工具版本已更改,但对工具的任何依赖性均未更改。我该怎么做?我已经或多或少地随机尝试过其他目标,并且我确实尝试过阅读手册。

我已经尝试使用 <dependencyManagement> 部分并使用父版本中的属性,但这些没有更新到新版本。

非常感谢任何帮助。

加法

我最多收到一条消息“忽略反应器依赖项:com.tool:tool:jar:null:1.2.3”。这是我尝试versions:use-latest-releases 的时候。但是,versions:display-dependency-updates 确实显示了“本地依赖项”的更新(功能测试取决于工具)。

更新

似乎 Maven 会从存储库中查找新版本,包括本地版本,现在我想到它似乎很明显。但是,这意味着必须在更新依赖项之前构建该工具并将其安装到本地存储库。

我只是想知道这是否是将集成测试作为他们自己的项目的正确方法。我希望有一种方法可以立即更新版本。

更新

基本上我有以下设置。 toolfunctional-tests 的版本依赖由parent 项目定义。我省略了tool-core,因为它可以作为tool 的一部分处理。

根:

<groupId>com.somecompany</groupId>
<artifactId>x-reactor</artifactId>
<packaging>pom</packaging>
<version>1.0</version>

<profiles>
    <profile>
        <id>cli</id>
        <modules>
            <module>tool</module>
        </modules>
    </profile>
    <profile>
        <id>deploy</id>
        <modules>
            <module>tool</module>
            <module>functional-tests</module>
        </modules>
    </profile>
</profiles>

父母:

<groupId>com.somecompany</groupId>
<artifactId>x-parent</artifactId>
<packaging>pom</packaging>
<version>1.0</version>

<dependencyManagement>
    <dependencies>
        <dependency>
            <groupId>com.somecompany</groupId>
            <artifactId>tool</artifactId>
            <version>3.2.3</version>
        </dependency>
    </dependencies>
</dependencyManagement>

工具:

<parent>
    <groupId>com.somecompany</groupId>
    <artifactId>x-parent</artifactId>
    <version>1.0</version>
    <relativePath>../parent/pom.xml</relativePath>
</parent>

<groupId>com.somecompany</groupId>
<artifactId>tool</artifactId>
<packaging>jar</packaging>
<version>3.2.3</version>

功能测试:

<parent>
    <groupId>com.somecompany</groupId>
    <artifactId>x-parent</artifactId>
    <version>1.0</version>
    <relativePath>../parent/pom.xml</relativePath>
</parent>

<groupId>functional-tests</groupId>
<artifactId>functional-tests</artifactId>
<version>0.1</version>
<packaging>pom</packaging>

<dependencies>
    <dependency>
        <groupId>com.somecompany</groupId>
        <artifactId>tool</artifactId>
    </dependency>
</dependencies>

【问题讨论】:

  • 你能给你不同模块的pom的sn-ps吗...(只有父部分和模块部分)。

标签: maven-2


【解决方案1】:

我目前在“use-releases”目标中遇到了同样的问题,并且很高兴版本插件(刚刚?)通过参数“excludeReactor=false支持这种情况>”! :-)

【讨论】:

    【解决方案2】:

    显然,必须在与需要更新的 pom.xml 所在的路径相同的路径中运行目标 versions:use-latest-versions。我通过将版本移动到父项目并仅更新它来解决这个问题。我对这个解决方案不太满意,因为版本插件似乎不支持降级版本。此外,新版本是从(本地)存储库中获取的,这意味着必须在更新版本之前构建该工具。我认为这是我最初的问题。

    这是解决此问题的脚本:

    #!/bin/bash
    
    if [[ $# -lt 1 ]]; then
        echo "Usage: $0 [version number]"
        exit 1
    fi
    
    function revert_version() {
        mvn -Pall versions:revert > /dev/null
        echo "ERROR: Failed updating the version"
        cat mvn_out.txt
        exit 1
    }
    
    v=$1
    profile=cli
    echo "Updating the version to $v..."
    mvn -P$profile versions:set -DnewVersion=$v -DartifactId=tool -q
    [ $? -eq 0 ] || revert_version
    
    echo "Building the tool..."
    mvn -P$profile install > /dev/null
    [ $? -eq 0 ] || revert_version
    
    echo "Updating the dependencies..."
    mvn versions:use-latest-versions -Dincludes=com.somecompany:* -f parent/pom.xml -q
    [ $? -eq 0 ] || revert_version
    mvn -Pall versions:commit -q
    [ $? -eq 0 ] || revert_version
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 2014-09-09
      • 2019-07-23
      • 2016-09-18
      • 2018-07-14
      • 2016-05-23
      • 2019-05-18
      • 1970-01-01
      相关资源
      最近更新 更多