如何仅针对多模块/反应堆构建中的依赖项自动更新版本? [英] How to auto-update versions only for dependencies within multi-module/reactor build?

查看:69
本文介绍了如何仅针对多模块/反应堆构建中的依赖项自动更新版本?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

当我为root项目运行以下命令时,它将检查所有依赖项的更新:

When I run the following command for the root project, it checks for updates of ALL dependencies:

mvn versions:use-latest-versions

我只想限制从root可以到达的那些依赖项的版本更新:

I want to limit versions update for only those dependencies which are reachable from the root:

root/pom.xml
├── A/pom.xml
│   └── D/pom.xml
│       └── E/pom.xml
├── B/pom.xml
└── C/pom.xml
    ├── F/pom.xml
    └── G/pom.xml

这些依赖项的组和工件ID在当前的反应堆版本(多模块版本)中.

The group and artifact ids of these dependencies are in the current reactor build (multi-module build).

例如,我不想更新诸如junitcommons-logging的外部依赖项.

For example, I don not want to update external dependencies like junit or commons-logging.

有一个选项 excludeReactor .而且我需要像 includeOnlyReactor 这样的对立物.

There is an option excludeReactor. And I need an opposite like includeOnlyReactor.

否则,通过

Otherwise, it is unreliable and tedious work to specify all possible artifact patterns "owned" by your project via includes option.

推荐答案

将模块依赖项版本设置为${project.version}的最佳做法是在root pom的dependencyMnaagement部分中执行此操作.

Set module dependencies version to ${project.version} Good practice is to do it in dependencyMnaagement section of root pom.

示例:

<project>
<modelVersion>4.0.0</modelVersion>
<groupId>com.mycompany.app</groupId>
<artifactId>my-app</artifactId>
<version>1.0.0</version>


<modules>
    <module>A</module>
    <module>B</module>
    <module>C</module>
</modules


<dependencyManagement>
    <dependency>
        <groupId>com.mycompany.app</groupId>
        <artifactId>A</artifactId>
        <version>${project.version}</version>
    </dependency>
    <dependency>
        <groupId>com.mycompany.app</groupId>
        <artifactId>B</artifactId>
        <version>${project.version}</version>
    </dependency>

    ...And so on....

    <dependency>
        <groupId>com.mycompany.app</groupId>
        <artifactId>G</artifactId>
        <version>${project.version}</version>
    </dependency>
</dependencyManagement>


</project>  

然后,只要您想在另一个模块中使用该模块(例如B中的模块G),就只需放置

Then whenever you want to use the module in another module (e.g. module G in B) you put just

<dependency>
    <groupId>com.mycompany.app</groupId>
    <artifactId>B</artifactId>
</dependency>

要更改项目的版本,请使用mvn versions:set.这将使所有模块保持相同的版本,并且依赖项管理部分还将保持依赖关系的相同版本.

To change version of the project use mvn versions:set. This will keep all the modules in the same version and the dependency management section will keep the dependencies in the same version as well.

很显然,如果您想一直将模块保持在同一版本中,将无法使用.但这反而会更加棘手.

Obviously it won't work if you want to keep your modules in same version all the time. But this will be more tricky anyway.

这篇关于如何仅针对多模块/反应堆构建中的依赖项自动更新版本?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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