gpt4 book ai didi

Java/Gradle : Any tips on centralizing dependency version control for a multiple repository project?

转载 作者:行者123 更新时间:2023-12-03 05:37:44 25 4
gpt4 key购买 nike

我厌倦了必须手动更改每个存储库的依赖版本并运行构建和测试。

是否有任何好的解决方案/工具可以集中处理,以便您只需更改一个文件中的版本?
一个要求是您仍然可以从本地存储库覆盖所需的版本。

最佳答案

在我的 Maven 项目中,我使用父 pom 进行依赖管理。我在父 pom 中使用“dependencyManagement”标签来声明所有可用的依赖项及其子模块的版本。

目录结构

- project-name
- module-A
- pom.xml
- pom.xml

在父 pom.xml 我指定 depencyManagement 标记:
<dependencyManagement>
<dependencies>
<dependency>
<groupId>com.test</groupId>
<artifactId>artifact</artifactId>
<version>1.0</version>
</dependency>
</dependencies>
</dependencyManagement>

在 module-A pom.xml 中有类似的东西:
<parent>
<artifactId>module-A</artifactId>
<groupId>com.test</groupId>
<version>1.0</version>
</parent>

<dependencies>
<!-- The version is inherited from parent pom -->
<dependency>
<groupId>com.test</groupId>
<artifactId>artifact</artifactId>
</dependency>
</dependencies>

这种方式只允许在父 pom.xml 中更改依赖项的版本。所有子模块都将使用它。

更多细节可以在 Maven 的官方文档中找到: https://maven.apache.org/guides/introduction/introduction-to-dependency-mechanism.html

关于Java/Gradle : Any tips on centralizing dependency version control for a multiple repository project?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/54978786/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com