【发布时间】:2013-02-19 16:57:13
【问题描述】:
我通常将<dependencyManagement> 部分放在parent-project/pom.xml 中。这个<dependencyManagement> 部分包含我的子模块的所有依赖项的声明和版本(即没有<scope> 元素):
<dependencyManagement>
<dependencies>
<dependency>
<groupId>junit</groupId>
<artifactId>junit</artifactId>
<version>4.10</version>
</dependency>
</dependencies>
</dependencyManagement>
在所有子模块(即 moduleX/pom.xml)中,我有:
<dependencies>
<dependency>
<groupId>junit</groupId>
<artifactId>junit</artifactId>
<scope>test</scope>
</dependency>
</dependencies>
显然,在此示例中,我为同一个依赖项重复<scope>test</scope> 多次(在每个需要 junit 的子模块中一次)。
我的问题是:
关于<scope> 声明的最佳实践是什么?
把它放在<dependencyManagement>中会更好吗?
还是将它放在子模块的<dependencies> 部分更好(就像在这篇文章中一样)?为什么?
这个问题有确定的答案吗?
【问题讨论】:
标签: maven dependency-management