Dependencymanagement and dependencies in maven

Source: Internet
Author: User

here is a description of the difference between declaring dependencymanagement and dependencies in the root node of the parent projectDependencymanagement

Maven uses the Dependencymanagement element to provide a way to manage dependent version numbers. The dependencymanagement element is typically seen in the parent pom at the top level of an organization or project. Using the Dependencymanagement element in Pom.xml can make
All references a dependency in a subproject without explicitly listing the version number. Maven walks up the parent-child hierarchy until a project with the dependencymanagement element is found, and then it uses the version number specified in the Dependencymanagement element.

For example, in the parent project:

XML code
  1. < Dependencymanagement >    
  2. < Dependencies >   
  3. < dependency >   
  4. < groupId > mysql</ groupId >   
  5. < artifactId > Mysql-connector-java</ artifactId >   
  6. < version > 5.1.2</ version >   
  7. </ Dependency >
  8. ...
  9. < Dependencies >   
  10. </ dependencymanagement >

You can then add mysql-connector to a subproject without specifying a version number, for example:

XML code
  1. < Dependencies >   
  2. < dependency >   
  3. < groupId > mysql</ groupId >   
  4. < artifactId > Mysql-connector-java</ artifactId >   
  5. </ dependency >   
  6. </ Dependencies >

The advantage of this is that if you have multiple sub-projects that reference the same dependency, you can avoid declaring a version number in each subproject, so that when you want to upgrade or switch to another version, you only need to update it in the top-level parent container, without the modification of a single subproject In addition, if a subproject requires a different version, you only need to declare version.

Dependencymanagement only declares dependencies and does not implement ingestion, so the subproject needs to explicitly declare the dependencies that need to be used.

Dependencies

As opposed to dependencymanagement, all claims in dependencies are automatically introduced and inherited by all sub-projects by default.

Dependencymanagement and dependencies in maven

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.