Spring IO Platform项目做为Spring的主要项目之一,其目的就是用来解决依赖包的版本问题。Spring IO Platform官方的定义是:html
Spring IO is a cohesive, versioned platform for building modern applications. It is a modular, enterprise-grade distribution that delivers a curated set of dependencies while keeping developers in full control of deploying only the parts they need. Spring IO is 100% open source, lean, and modular.
Spring IO 是一个用于构建现代应用程序的、有凝聚力的版本化平台。它是一个模块化的、企业级的分布,提供了一组策略依赖关系。同时,开发人员只需部署他们所须要的部分。Spring IO是100%开源、精益和模块化的项目。spring
在构建项目时,常常会使用到第三方库,通常你们都是根据经验或直接选择较新的版本,随意性较大。随着业务复杂度的增长,集成的第三方库会愈来愈多,依赖关系也会愈来愈复杂。除非作过完整的测试,保证集成第三方库的版本不会出问题,且后续集成或升级都不会出问题,不然就有可能存在较大的隐性风险(版本冲突)。服务器
Spring IO Platform就能很好地帮助咱们解决这些问题。开发人员在添加第三方库时,不须要关心版本号,Spring IO Platform会帮助咱们提供一个最优的版本,并且该版本是通过严格测试的,能够更好地兼容其它的组件。同时,你也能够根据本身的须要来升级或降级依赖版本。app
Spring IO Platform的主要特征:maven
若是你准备使用Spring IO Platform,建议到官网获取最新的项目版本:https://platform.spring.io/pl...。模块化
本文编写时的最新版本:Brussels-SR6
在Maven项目中添加以下依赖管理:spring-boot
<dependencyManagement> <dependencies> <dependency> <groupId>io.spring.platform</groupId> <artifactId>platform-bom</artifactId> <version>Brussels-SR6</version> <type>pom</type> <scope>import</scope> </dependency> </dependencies> </dependencyManagement>
在Gradle项目中添加以下依赖管理:工具
buildscript { repositories { jcenter() } dependencies { classpath 'io.spring.gradle:dependency-management-plugin:1.0.0.RELEASE' } } apply plugin: 'io.spring.dependency-management' dependencyManagement { imports { mavenBom 'io.spring.platform:platform-bom:Brussels-SR6' } }
在集成Spring IO Platform提供的依赖管理后,你仍然能够像平时同样添加第三方库,只是无需再关心依赖包的版本:学习
查看全部依赖包的版本信息: https://docs.spring.io/platfo...
<dependency> <groupId>org.springframework</groupId> <artifactId>spring-core</artifactId> </dependency>
dependencies { compile 'org.springframework:spring-core' }
Spring IO Platform项目集成的第三方库的版本信息都是使用<properties />
来定义的,这就使得你能够很容易的升级或降级某个依赖包的版本。在你的项目中指定依赖包的版本号:测试
<properties> <foo.version>1.2.0.RELEASE</foo.version> </properties>
在使用Spring IO Platform项目的依赖管理时,应根据项目的实际运行环境来合理选择版本号,除非必须,不然不建议修改版本信息。在修改依赖包的版本信息时,可经过IDE点击坐标来查看依赖包对应的属性名。
Spring IO Platform项目的本质就是一个pom文件,它记录了Spring项目和其它第三方库对应的版本信息。因为Spring IO Platform项目帮助咱们作了大量的集成和测试工做,使得咱们能够轻松使用。
现在,使用Spring Boot的项目也愈来愈多,它的spring-boot-dependencies
模块就是一个相似Spring IO Platform的项目,二者的区别就是集成的依赖包和插件有所不一样。
在企业级项目开发和管理中,Spring IO Platform项目绝对是值得你花时间去学习和研究的。你能够在Spring IO Platform项目的基础上进行改进,增长一些国产开源项目的集成和企业私有库的管理,构建企业内部的项目版本平台,促进企业项目的统一管理。