前往小程序,Get更优阅读体验!
立即前往
首页
学习
活动
专区
工具
TVP
发布
社区首页 >专栏 >Spring IO Platform 解决Spring项目组合中版本依赖

Spring IO Platform 解决Spring项目组合中版本依赖

作者头像
壮壮熊
修改2023-01-17 14:55:10
5920
修改2023-01-17 14:55:10
举报
文章被收录于专栏:程序猿牧场程序猿牧场

简介:

    Spring IO Platform是Spring官网中排第一位的项目。它将Spring的核心API集成到一个适用于现代应用程序的平台中。提供了Spring项目组合中的版本依赖。这些依赖关系是经过测试,可以保证正常工作。

为什么要使用?

    Spring IO Platform主要是解决依赖版本的冲突问题。举个栗子:在使用Spring的时候,经常会使用到第三方库,一般大家都是根据经验挑选一个版本浩或挑选最新的,其实这是存在隐患的。除非做过完整的测试,保证集成该版本的依赖不会出现问题,否则风险很大,且后续扩展会越来越困难。因为随着业务复杂度的增加,集成的第三方组件会越来会多,依赖之间的关联也会也来越复杂。
    Spring IO Platform正好解决了这些问题,在我们添加第三方依赖时,不需要写版本号,它能自动帮我们选择一个最优的版本,保证最大限度的扩展。

维护了哪些依赖?

    Spring IO Platform维护的依赖非常多,挑选了一些常见的(更多详情请查看官网),如下表所示:

Group

Artifact

Version

org.springframework.boot

spring-boot

1.5.10.RELEASE

ch.qos.logback

logback-core

1.1.11

com.google.code.gson

gson

2.8.2

com.rabbitmq

amqp-client

4.0.3

com.rabbitmq

http-client

1.1.1.RELEASE

junit

junit

4.12

org.apache.tomcat

tomcat-jdbc

8.5.27

使用Spring IO Platform

    Spring IO Platform主要用于管理系统依赖,可以支持Maven和Gradle。

在Maven中使用Spring IO Platform

    Spring IO Platform支持import和继承parent两种方式:
    import的方式:
<?xml version="1.0" encoding="UTF-8"?>
<project xmlns="http://maven.apache.org/POM/4.0.0"
         xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
         xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">

    <modelVersion>4.0.0</modelVersion>

    <groupId>com.example</groupId>
    <artifactId>your-application</artifactId>
    <version>1.0.0-SNAPSHOT</version>

    <dependencyManagement>
        <dependencies>
            <dependency>
                <groupId>io.spring.platform</groupId>
                <artifactId>platform-bom</artifactId>
                <version>Brussels-SR7</version>
                <type>pom</type>
                <scope>import</scope>
            </dependency>
        </dependencies>
    </dependencyManagement>
    <!-- Dependency declarations -->
</project>
    继承parent的方式:
<?xml version="1.0" encoding="UTF-8"?>
<project xmlns="http://maven.apache.org/POM/4.0.0"
         xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
         xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
    <modelVersion>4.0.0</modelVersion>
    <groupId>com.example</groupId>
    <artifactId>your-application</artifactId>
    <version>1.0.0-SNAPSHOT</version>
    <parent>
        <groupId>io.spring.platform</groupId>
        <artifactId>platform-bom</artifactId>
        <version>Brussels-SR7</version>
        <relativePath/>
    </parent>
    <!-- Dependency declarations -->
</project>
    采用继承parent的方法,除了导入pom提供的依赖关系管理之外,应用程序还将获得一些插件管理,为许多插件提供合理的默认设置,包括Spring Boot的Maven插件。 要利用这个默认配置,需要做的就是把这个插件包含在你的pom的<plugins>部分中:
<build>
    <plugins>
        <plugin>
            <groupId>org.springframework.boot</groupId>
            <artifactId>spring-boot-maven-plugin</artifactId>
        </plugin>
    </plugins>
</build>
    当想在自己的pom里添加了一个属于Spring IO Platform中的依赖的时候,可以直接省略版本号,如下所示:
<dependencies>
    <dependency>
        <groupId>org.springframework</groupId>
        <artifactId>spring-core</artifactId>
    </dependency>
</dependencies>

在Gradle中使用Spring IO Platform

    如下所示,我们会应用io.spring.dependency-management这个插件,然后在dependencyManagement中导入bom
buildscript {
    repositories {
        jcenter()
    }
    dependencies {
        classpath 'io.spring.gradle:dependency-management-plugin:1.0.0.RELEASE'
    }
}
apply plugin: 'io.spring.dependency-management'
repositories {
    mavenCentral()
}
dependencyManagement {
    imports {
        mavenBom 'io.spring.platform:platform-bom:Brussels-SR7'
    }
}
    当需要添加一个属于Spring IO Platform中的依赖的时候,写法与Maven类似,可以省略版本号,如下所示:
dependencies {
    compile 'org.springframework:spring-core'
}
本文参与 腾讯云自媒体分享计划,分享自微信公众号。
原始发表:2018-02-26,如有侵权请联系 cloudcommunity@tencent.com 删除

本文分享自 程序猿牧场 微信公众号,前往查看

如有侵权,请联系 cloudcommunity@tencent.com 删除。

本文参与 腾讯云自媒体分享计划  ,欢迎热爱写作的你一起参与!

评论
登录后参与评论
0 条评论
热度
最新
推荐阅读
领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档