
当我们使用 spring 或 spring-boot 开发项目时,需要引入很多依赖,包括 spring 本身的组件、各种 spring-boot-starter、以及其它第三方依赖(如:slf4j、redis)。
依赖多了,版本的选择是个问题,就怕哪个版本选择的不对导致出现一些意想不到的 BUG。
比如下面这个例子:
1 | <dependencies> |
slf4j 的 1.7.26 版本、postgresql 的 42.2.14 版本和 spring 的 5.2.10.RELEASE 版本会不会有冲突呢???
于是 spring 提供了 spring-boot-dependencies 用于方便管理项目的依赖,只需在 dependencyManagement 里面配置好 spring-boot-dependencies 的版本,在 dependencies 里面就不用再指定其它版本号了,如:
1 | <dependencyManagement> |
其实 spring-boot-dependencies 就是一个 pom.xml,里面管理了很多常见第三方的依赖和版本。
在 spring-boot-dependencies 出现之前,spring 还出现过 platform-bom。
1 | <dependencyManagement> |
也是类似的功能,帮助管理版本号。不过好像现在这个 platform-bom 已经不再维护了,建议统一使用 spring-boot-dependencies。