Differences between dependencymanagement and dependencies in maven

来源:互联网 发布:汤臣倍健跟安利 知乎 编辑:程序博客网 时间:2024/05/29 05:53

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

阅读全文
0 0
原创粉丝点击