[Maven project management tool] Introduction to the use of dependencyManagement

Introduction to the use of dependencyManagement

The dependencyManagement element in Maven provides a way to manage dependency version numbers. Declare information such as the version number of the dependent jar package in the dependencyManagement element, then all subprojects do not need to explicitly list the version number when the dependent jar package is introduced again. Maven will go up the parent-child hierarchy to find the project with the dependencyManagement element, and then use the version number it specifies.

For example

Configure in the pom.xml of the parent project

<dependencyManagement>
   <dependencies>
         <dependency>
             <groupId>org.springframework.boot</groupId>
             <artifactId>spring-boot-starter-web</artifactId>
             <version>1.2.3.RELEASE</version>
         </dependency>
     </dependencies>
</dependencyManagement>

This configuration is the version information of spring-boot.

No need to specify version information for sub-projects

<dependency>
    <groupId>org.springframework.boot</groupId>
    <artifactId>spring-boot-starter-web</artifactId>
</dependency>

Advantages of use

If there are multiple sub-projects that all reference the same dependency, you can avoid declaring a version number in each sub-project used. When you want to upgrade or switch to another version, you only need to update in the top-level parent container without modifying the sub-projects one by one; in addition, if a sub-project requires another version, you only need to declare the version.

Precautions

What is defined in dependencyManagement is only the declaration of dependencies, and does not implement the introduction, so the subproject needs to explicitly declare the dependencies that it needs.

Guess you like

Origin blog.csdn.net/weixin_42825651/article/details/114060178