[英]Java/Gradle: Any tips on centralizing dependency version control for a multiple repository project?
我厭倦了必須手動更改每個存儲庫的依賴版本並運行構建和測試的方法。
是否有任何好的解決方案/工具可以將其集中化,因此您只需要在一個文件中更改版本? 要求是您仍然可以覆蓋本地存儲庫中的所需版本。
在我的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
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.