ReturnTmp's Blog ReturnTmp's Blog
首页
基础课程
编程语言
框架技术
运维笔记
人工智能
随笔摘录
  • 友链
关于
收藏
  • 分类
  • 标签
  • 归档
GitHub (opens new window)

ReturnTmp

分享有趣好玩的计算机知识
首页
基础课程
编程语言
框架技术
运维笔记
人工智能
随笔摘录
  • 友链
关于
收藏
  • 分类
  • 标签
  • 归档
GitHub (opens new window)
  • GLIBC_2.28 not found 问题解决
  • Monorepo 多项目单仓库
  • Renovate 第三方依赖更新监控
  • 【IDEA】Maven 构建项目生成文件解析
  • K8s

  • Zotero 使用指南
  • package-lock.json 是否提交问题
  • 『ARM』和『x86』处理器架构解析指南
  • GlassFish 安装配置
  • 手把手教你安装配置『Oracle Database 19c』
  • Oracle Database 19c 彻底卸载
  • 语雀故障回顾
  • OpenStack 云计算平台 Nova 计算服务学习指南
  • Vue devServer 教程
  • Swagger 导出 API 文档
  • MapStruct POJO 映射框架指南
  • IDEA 代码热部署和热加载
  • SpringBoot 启动参数配置
  • Nacos 入门指南
  • seleuim 指南
  • Spring 服务降级熔断
  • Maven BOM 解析
    • 前言
    • 配置
    • 使用
    • 补充
    • 参考链接
  • .vscode 文件夹
  • Spring Security Token 认证
  • SpringBoot 基于 Actuator 和 Admin 实现应用监控管理
  • SPM/SCM 流量跟踪体系
  • Netty 入门
  • Flyway 数据库版本管理实战指南
  • Swagger 2 和 3 安装区别
  • MP 配置分页
  • MySQL 分库分表
  • Git Commit 提交规范,变更日志、版本发布自动化和 Emoji 提交标准
  • VSCode 插件 i18n Ally 进行国家化配置
  • Vue3 组合式 全局挂载
  • TS 教程
  • 架构解析:同城双活、异地多活、单元化架构
  • Spring 跨域配置
  • SpringCloud 微服务实战
  • Sentinel 流量治理组件教程
  • leetcode 上分
  • JMeter 压测
  • Netty IM 系统
  • IDEA 插件开发
  • SpringBoot 邮件服务 集成配置 详解
  • Maven 依赖包冲突问题解决
  • 社区项目 forest 修改
  • Maven 项目命名规范
  • 新版 PyCharm 设置 Conda 虚拟环境
  • 框架工具
ReturnTmp
2023-11-15
目录

Maven BOM 解析

# 前言

BOM(Bill of Materials)是由 Maven 提供的功能,它通过定义相互兼容的 jar 包版本集合,

使用时只需要依赖该 BOM 文件,即可放心的使用需要的依赖 jar 包,且无需再指定版本号。

BOM 的维护方负责版本升级,并保证 BOM 中定义的 jar 包版本之间的兼容性

使用 BOM 可以有效解决依赖冲突问题,同时子项目减轻标注版本号的负担

# 配置

BOM 本质上是普通的 POM 文件,区别是对于使用方而言,生效的只有 <dependencyManagement>这部分,我们只需要在<dependencyManagement>定义对外发布的客户端版本即可

下面我以 yudao 代码为例,创建 yudao-dependencies 模块,然后模块中只创建文件 pom.xml

<groupId>cn.iocoder.boot</groupId>  
<artifactId>yudao-dependencies</artifactId>  
<version>${revision}</version>  
<packaging>pom</packaging>

<dependencyManagement>
    <dependencies>
		<!-- 统一依赖管理 -->  
		<dependency>  
		    <groupId>org.springframework.boot</groupId>  
		    <artifactId>spring-boot-dependencies</artifactId>  
		    <version>${spring.boot.version}</version>  
		    <type>pom</type>  
		    <scope>import</scope>  
		</dependency>

		<dependency>  
		    <groupId>com.github.xiaoymin</groupId>  
		    <artifactId>knife4j-openapi3-spring-boot-starter</artifactId>  
		    <version>${knife4j.version}</version>  
		</dependency>
    </dependencies>
</dependencyManagement>
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23

spring-boot-dependencies依赖包里面声明了各种版本号,供其他项目(模块)去引用

除此之外,也可以像里面的 knife4j 单独配置依赖版本

# 使用

然后回到父项目 pom.xml ,我们需要向节点 dependencyManagement 中添加我们刚刚 BOM 模块信息

<dependencyManagement>  
    <dependencies>  
        <dependency>  
            <groupId>cn.iocoder.boot</groupId>  
            <artifactId>yudao-dependencies</artifactId>  
            <version>${revision}</version>  
            <type>pom</type>  
            <scope>import</scope>  
        </dependency>  
    </dependencies>  
</dependencyManagement>
1
2
3
4
5
6
7
8
9
10
11

之后其他子项目即可使用 BOM 中配置的依赖

# 补充

我们以 yudao 为例,本质上还是个单体项目,其实直接在根目录 pom.xml (opens new window) (opens new window) 管理依赖版本会更加方便,也符合绝大多数程序员的认知

那么为什么还要额外配置 BOM 模块呢,我们额外考虑场景,如果每个 yudao-module-xxx 模块都维护在一个独立的 Git 仓库,那么 yudao-dependencies 就可以在多个 yudao-module-xxx 模块实现复用。比较方便

# 参考链接

  • Maven BOM!拿来吧你 - 掘金 (juejin.cn) (opens new window)
编辑 (opens new window)
上次更新: 2023/11/28, 12:55:10
Spring 服务降级熔断
.vscode 文件夹

← Spring 服务降级熔断 .vscode 文件夹→

最近更新
01
百度网盘加速
03-24
02
新版 PyCharm 设置 Conda 虚拟环境
03-24
03
腾讯云域名转到阿里云
03-24
更多文章>
Theme by Vdoing | Copyright © 2023-2024 ReturnTmp | MIT License
  • 跟随系统
  • 浅色模式
  • 深色模式
  • 阅读模式