Java / Gradle:关于集中多个仓库项目的依赖版本控制的任何技巧?

时间:2019-03-04 07:52:40

标签: java gradle dependencies version centralized

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

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

1 个答案:

答案 0 :(得分:0)

在我的Maven项目中,我使用父pom进行依赖项管理。我在父pom中使用“ dependencyManagement”标签来声明所有可用的依赖关系,以及他对子modoules的版本。

目录结构

- 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>

在模块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中更改依赖项的版本。 Al子模块将使用它。

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

相关问题