问题:
What is the difference between dependencyManagement
and dependencies
? dependencyManagement
和dependencies
什么区别? I have seen the docs at Apache Maven web site. 我已经在Apache Maven网站上看到了这些文档。 It seems that a dependency defined under the dependencyManagement
can be used in its child modules without specifying the version. 似乎可以在依赖项管理下定义的dependencyManagement
在其子模块中使用,而无需指定版本。
For example: 例如:
A parent project (Pro-par) defines a dependency under the dependencyManagement
: 父项目(专业人士)在dependencyManagement下定义了一个dependencyManagement
:
<dependencyManagement>
<dependencies>
<dependency>
<groupId>junit</groupId>
<artifactId>junit</artifactId>
<version>3.8</version>
</dependency>
</dependencies>
</dependencyManagement>
Then in the child of Pro-par, I can use the junit: 然后在Pro-par的子级中,我可以使用junit:
<dependencies>
<dependency>
<groupId>junit</groupId>
<artifactId>junit</artifactId>
</dependency>
</dependencies>
However, I wonder if it is necessary to define junit in the parent pom? 但是,我想知道是否有必要在父pom中定义junit吗? Why not define it directly in the needed module? 为什么不直接在所需的模块中定义它?
解决方案:
参考一: https://stackoom.com/question/AzTa/Maven中dependencyManagement和依赖关系之间的区别参考二: https://oldbug.net/q/AzTa/Differences-between-dependencyManagement-and-dependencies-in-Maven
来源:oschina
链接:https://my.oschina.net/u/4432649/blog/4338132