我厌倦了必须手动更改每个存储库的依赖版本并运行构建和测试。
是否有任何好的解决方案/工具可以集中处理,以便您只需更改一个文件中的版本?一个要求是您仍然可以从本地存储库覆盖所需的版本。
我厌倦了必须手动更改每个存储库的依赖版本并运行构建和测试。
是否有任何好的解决方案/工具可以集中处理,以便您只需更改一个文件中的版本?一个要求是您仍然可以从本地存储库覆盖所需的版本。
在我的 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