1.maven中dependencyManagement标签;
a.使用dependencyManagement可以统一管理项目的版本号,确保应用的各个项目的依赖和版本一致;
2.dependencyManagement与dependencies的区别;
1)Dependencies相对于dependencyManagement,所有在dependencies里的依赖都会自动引入,
并默认被所有的子项目继承。
2)dependencyManagement里只是声明依赖,并不自动实现引入,因此子项目需要显示的声明需要用的依赖。
如果不在子项目中声明依赖,是不会从父项目中继承下来的;只有在子项目中写了该依赖项,并且没有指
定具体版本,才会从父项目中继承该项,并且version和scope都读取自父pom;另外如果子项目中指定了版
本号,那么会使用子项目中指定的jar版本。
1.在父项目中使用dependencyManagement标签管理jar
<properties>
<springcould.version>Greenwich.RELEASE</springcould.version>
</properties>
<dependencyManagement>
<dependencies>
<!--springCould的依赖-->
<dependency>
<groupId>org.springframework.cloud</groupId>
<artifactId>spring-cloud-dependencies</artifactId>
<version>${springcould.version}</version>
<type>pom</type>
<scope>import</scope>
</dependency>
</dependencies>
</dependencyManagement>
2.在子项目中使用dependencies声明依赖,版本信息会从父项目中继承过来;
<dependencies>
<!--springCould的依赖-->
<dependency>
<groupId>org.springframework.cloud</groupId>
<artifactId>spring-cloud-dependencies</artifactId>
</dependency>
</dependencies>
3.在子项目中定义了版本信息,则使用子项目中定义的版本;
<properties>
<springcould.version>Greenwich.SR2</springcould.version>
</properties>
<dependencies>
<!--springCould的依赖-->
<dependency>
<groupId>org.springframework.cloud</groupId>
<artifactId>spring-cloud-dependencies</artifactId>
<version>${springcould.version}</version>
</dependency>
</dependencies>