父项目做依赖管理
父项目声明非常多的依赖,子项目继承父项目,那么子项目引入依赖时就不需要再写版本号
依赖管理
<parent>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-parent</artifactId>
<version>2.3.4.RELEASE</version>
</parent>
项目的父项目如下:
<parent>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-dependencies</artifactId>
<version>2.3.4.RELEASE</version>
</parent>
它几乎声明了所有开发中常用的依赖的版本号,自动版本仲裁机制
依赖的版本号都是在spring-boot-dependencies父项目中进行统一管理的
开发导入starter场景启动器
见到很多 spring-boot-starter-* : *就某种场景
只要引入starter,这个场景的所有常规需要的依赖我们都自动引入
见到的 *-spring-boot-starter: 第三方为我们提供的简化开发的场景启动器。
所有场景启动器最底层的依赖
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter</artifactId>
<version>2.3.4.RELEASE</version>
<scope>compile</scope>
</dependency>
无需关注版本号,自动版本仲裁
- 引入依赖默认都可以不写版本
- 引入非版本仲裁的jar,要写版本号。
可以修改默认版本号
查看spring-boot-dependencies里面规定当前依赖的版本 用的 key。
-
在当前项目的 pom.xml 里面重写配置,如下面的代码。
<properties> <mysql.version>5.1.43</mysql.version> </properties>
第一步是查看spring-boot-dependencies父项目里面规定的当前依赖的版本号所用的key(即标签,例如<mysql.version></mysql.version>)
第二步是在当前maven项目的pom.xml文件里面使用该key重写当前依赖的版本号
maven提供的特性:就近优先原则,只要当前maven项目里面就近配置了依赖的版本号,那就使用就近配置的,否则才会使用父项目中统一管理的。