如何使用Versions Maven Plugin更新依赖兄弟模块的版本 [英] How to update version on dependent sibling module with Versions Maven Plugin

查看:124
本文介绍了如何使用Versions Maven Plugin更新依赖兄弟模块的版本的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

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

I have an issue with updating the dependency version of dependent sibling projects.

我的简化项目设置如下.

My simplified project setup is the following.

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

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

The parent project holds all the global properties and dependency management. The functional tests depend on the tool and the tool depends on the tool-core. The root pom.xml only aggregates (specifies whether the functional tests are included) and the parent project is the parent for all of the projects. I don't know if this is trivial, but the parent is not included in the aggregation though, as it already is the parent for each child project.

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

Now, my problem is if I change the version of tool with versions:set. The tool version is changed but any dependency to the tool is not. How should I do this? I have already tried more or less randomly other goals and I did try to read the manual.

我已经尝试过使用 <dependencyManagement> 部分并使用父版本中的属性,但这些不会更新到新版本.

I've tried already using the <dependencyManagement> section and using a property for the version in the parent but these do not get updated to the new version.

非常感谢任何帮助.

添加

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

I get a message "Ignoring reactor dependency: com.tool:tool:jar:null:1.2.3" at best. This is when I try to versions:use-latest-releases. However, versions:display-dependency-updates does show that there is an update on a "local dependency" (functional-tests depend on tool).

更新

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

It seems that Maven do lookups for new versions from the repositories, including the local one which seems quite obvious now that I think of it. However, this means that the tool has to be built and installed to local repository before updating the dependencies.

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

I'm only wondering if this is the right way to have integration tests as their own project. I was hoping that there would be a way to update the version straight away.

更新

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

Basically I have the following setup. The version dependency on functional-tests of the tool is defined by the parent project. I have omitted the tool-core since it can be handled as part of the 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.xml 所需的相同路径中运行目标 versions:use-latest-versions更新位于.我通过将版本移动到父项目并仅更新它来解决这个问题.我对这个解决方案不太满意,因为版本插件似乎不支持降级版本.此外,新版本是从(本地)存储库获取的,这意味着必须在更新版本之前构建该工具.我认为这是我最初的问题.

Apparently one has to run the goal versions:use-latest-versions in the same path as where the pom.xml one needs to update is located. I solved this by moving the versions to the parent project and updating only that. I'm not too satisfied with this solution since it seems that the versions plugin does not support downgrading the version. Also, the new version is aquired from the (local) repository which means that the tool has to be built before updating the version. I think this was my problem initially.

这是解决这个问题的脚本:

Here's the script to solve this problem:

#!/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

这篇关于如何使用Versions Maven Plugin更新依赖兄弟模块的版本的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆