SpringBoot源码系列(1):版本仲裁

布鸽不鸽 Lv4

前言

我们在使用SpringBoot框架时,依赖项可以不写版本号。这背后是通过SpringBoot的版本仲裁实现的。本文中SpringBoot版本号为2.7.5。

原文地址:https://xuedongyun.cn/post/63124/

版本依赖的位置

创建SpringBoot项目后,我们可以看到本项目的父项目,为spring-boot-starter-parent。按住Ctrl点击进入

1
2
3
4
5
<parent>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-parent</artifactId>
<version>2.7.5</version>
</parent>

spring-boot-starter-parent的父项目为spring-boot-dependencies。进入

1
2
3
4
5
<parent>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-dependencies</artifactId>
<version>2.7.5</version>
</parent>

spring-boot-dependencies中几乎申明了所有常见依赖的版本号,以properties的形式存储。

1
2
3
4
5
6
7
<properties>
<activemq.version>5.16.5</activemq.version>
<antlr2.version>2.7.7</antlr2.version>
<appengine-sdk.version>1.9.98</appengine-sdk.version>
<artemis.version>2.19.1</artemis.version>
...
</properties>

版本仲裁:

  • 父项目声明了常用依赖的版本号,其他依赖无需写版本号(自动版本仲裁)

自定义版本

直接写明版本号

1
2
3
4
5
6
<dependency>
<groupId>com.mysql</groupId>
<artifactId>mysql-connector-j</artifactId>
<version>8.0.31</version>
<scope>runtime</scope>
</dependency>

除开直接写版本号外,还可以在自己项目中利用properties声明版本号

1
2
3
<properties>
<mysql.version>8.0.21</mysql.version>
</properties>

starter命名规则

  • starter
    • 引入某种场景的依赖
    • 官方:spring-boot-starter-*
    • 第三方:*-spring-boot-starter

所有spring-boot-starter-*最基本的依赖都是spring-boot-starter

  • 标题: SpringBoot源码系列(1):版本仲裁
  • 作者: 布鸽不鸽
  • 创建于 : 2023-04-23 15:23:32
  • 更新于 : 2023-06-26 09:30:56
  • 链接: https://xuedongyun.cn//post/63124/
  • 版权声明: 本文章采用 CC BY-NC-SA 4.0 进行许可。
评论
此页目录
SpringBoot源码系列(1):版本仲裁