Maven中dependencyManagement和依赖关系之间的区别

点点圈 提交于 2020-08-19 05:30:28

问题:

What is the difference between dependencyManagement and dependencies ? dependencyManagementdependencies什么区别? 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
标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!