文章目录
一、需求背景
因为在有维护比较多的Android项目,在最近升级的过程总是出现最低版本编译(minCompileSdk
)错误,所以决定创建相关BOM
帮助自己的对一些老项目进行升级,这些项目有些准备升级到33,有些升级31,新的项目直接34
Dependency 'androidx.xxxxx.xxx' requires libraries and applications that
depend on it to compile against version 34 or later of the Android APIs.
启发来自 Compose Bom,刚好学习一下相关知识,然后做一点记录。
二、BOM介绍
BOM (Bill Of Material) 是 Maven 仓库中的一个概念,它本质也是一个可被引用的包,但不包含代码,只是声明了一系列其它包。
- 方便使用者在声明依赖的客户端时不需要指定版本号外,
- 最主要的原因是可以解决依赖冲突
Bom 通常是项目中单独的一个模块,即只有单个pom.xml文件的module,并配合 dependencyManagement 等标签实现项目的全局依赖统一管理
三、利用Gradle创建BOM
首先我们都知道BOM本质上是一个普通的POM文件,区别是对于使用方而言,生效的只有 <dependencyManagement>
这一个部分。
示例:
<dependencyManagement>
<dependencies>
<!-- 统一依赖管理 -->
<dependency>
<groupId>xxxx.xxx</groupId>
<artifactId>xxx</artifactId>
<version>1.0</version>
</dependency>
<dependency>
<groupId>xxxx.xxx</groupId>
<artifactId