maven中dependencymanagement的作用

dependencymanagement通常存在于父项目的pom.xml文件中,提供了一种管理依赖版本号的方式。

使用pom.xml 中的dependencyManagement 元素能让子项目中引用依赖时不需要注明版本号。Maven会沿着父子层级向上寻找dependencyManagement元素,使用它指定的版本号。

父项目的pom.xml文件

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

子项目的pom.xml文件

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

如果想要切换版本号只需要将父项目的pom文件修改即可,不需要逐个修改子项目,大大提高了效率。

posted @ 2021-05-18 20:06  lbeaner  阅读(503)  评论(0)    收藏  举报