使用Maven管理项目依赖的一大好处就是能够方便的进行依赖版本管理,但是
dependencyManagement和dependencies的概念有点混淆,今天把它弄清楚了,记录一下。
1 | <dependencyManagement> |
在dependencyManagement中的依赖不会被子模块继承,仅仅是为了进行版本管理,子模块需要引入groupId和artifactId,如果也引入了version则以子模块为主,类似重写的概念。1
2
3
4
5
6
7
8
9<dependencies>
<dependency>
<groupId>org.springframework.cloud</groupId>
<artifactId>spring-cloud-dependencies</artifactId>
<version>${spring-cloud.version}</version>
<type>pom</type>
<scope>import</scope>
</dependency>
</dependencies>
在主模块dependencies下的依赖会直接被子模块继承,如果你的子模块需要依赖一个公共的库可以加在这里方便管理。