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

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

最佳答案

在我的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>

在模块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

08-18 03:47
查看更多