码迷,mamicode.com
首页 > 其他好文 > 详细

maven-dependencyManagement

时间:2018-05-03 12:08:08      阅读:109      评论:0      收藏:0      [点我收藏+]

标签:dependencyManagement

在使用maven去build项目时,很多时候会在parent的pom文件中看到如下代码:

    <dependencyManagement>
        <dependencies>
            <dependency>
                <groupId>org.springframework.boot</groupId>
                <artifactId>spring-boot</artifactId>
                <version>2.0.1.RELEASE</version>
            </dependency>
            <dependency>
                <groupId>org.springframework.boot</groupId>
                <artifactId>spring-boot-test</artifactId>
                <version>2.0.1.RELEASE</version>
            </dependency>
            <dependency>
                <groupId>org.springframework.boot</groupId>
                <artifactId>spring-boot-test-autoconfigure</artifactId>
                <version>2.0.1.RELEASE</version>
            </dependency>
        </dependencyManagement>

那么<dependencyManagement>与<dependency>有什么区别呢?

  • <dependency>是用于直接引入jar,需要实际导入到classpath中。
  • <dependencyManagement>相当于对依赖进行版本的管理,并不会直接下载需要的依赖。而只是做一个版本的引用记录。它的目的主要是统一jar的引用(多个module)。因此,此标签通常是在parent中。

那么<dependencyManagement>与<dependency>有什么联系呢?

  • 当使用<dependency>引入依赖的时候,可以不设置<version>。这个时候,就从<dependencyManagement>去查找对应的依赖,如果存在,则直接下载对应的版本依赖。如果没有,则会报错并提示设置<version>。
  • 如果<dependency>设置了版本号,则会下载对应的版本jar而忽略<dependencyManagement>的依赖管理。

maven-dependencyManagement

标签:dependencyManagement

原文地址:http://blog.51cto.com/881206524/2112074

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!