Differences between dependencymanagement and dependencies in maven

本文详细解释了Maven中依赖管理和独立依赖的概念及其用法。依赖管理允许在父项目中集中管理多个项目的依赖版本,而独立依赖则声明了项目实际使用的依赖。通过这两种方式可以有效地统一版本控制并减少配置负担。

摘要生成于 C知道 ,由 DeepSeek-R1 满血版支持, 前往体验 >

In dependencyManagement you declare dependency versions, exclusions and other things that let you manage them in place (e.g. a parent pom) for multiple projects.

  • Dependency Management allows to consolidate and centralize the management of dependency versions without adding dependencies which are inherited by all children. This is especially useful when you have a set of projects (i.e. more than one) that inherits a common parent.
  • Another extremely important use case of dependencyManagement is the control of versions of artifacts used in transitive dependencies. This is hard to explain without an example. Luckily, this is illustrated in the documentation.
  • Artifacts specified in the <dependencyManagement> section, will only be included in the child module if they were also specified in the <dependencies> section of the child module itself. Why is it good you ask? because you specify the version and/or scope in the parent, and you can leave them out when specifying the dependencies in the child POM. This can help you use unified versions for dependencies for child modules, without specifying the version in each child module.

In dependencies you then declare the actual usage/need of a dependency and if the dependency is managed in a parent pom you can do so without using a version and it will be inherited and therefore be consistant across your usages downstream of the the parent pom. 

  • A dependency defined under the dependencyManagement can be used in it's child modules without specifying the version.
  • Artifacts specified in the <dependencies> section will ALWAYS be included as a dependency of the child module(s).


references: https://stackoverflow.com/questions/2619598/differences-between-dependencymanagement-and-dependencies-in-maven

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值