The Spring IO Platform framework is simply a version number compatible system, which organizes compatible versions of commonly used third-party class libraries. As long as we reference Spring IO Platform in our project, we do not need to set the version number for these third-party class libraries. Spring IO Platform will automatically help us set all compatible version numbers. This article is referenced from the official document. If you need to check the detailed information, please read the original text directly.
Introduce class library
Using Maven
If you use Maven, modify it to something like this in pom.xml.
<?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> <!-- Add the following paragraph --> <dependencyManagement> <dependencies> <dependency> <groupId>io.spring.platform</groupId> <artifactId>platform-bom</artifactId> <version>Brussels-SR3</version> <type>pom</type> <scope>import</scope> </dependency> </dependency> </dependency> </dependencyManagement> <!-- Dependency declarations --></project>
Or you can set Spring IO Platform as the parent project.
<?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-SR3</version> <relativePath/> </parent> <!-- Dependency declarations --></project>
After the setup is completed, you do not need to specify the version to add dependencies later. You can add dependencies like this.
<dependencies> <dependency> <groupId>org.springframework</groupId> <artifactId>spring-core</artifactId> <!-- No version number--> </dependency></dependencies>
Using Gradle
If you use Gradle, it will be a little more complicated. Because Gradle does not have the function of dependencyManagement, additional plug-ins are needed. In short, just modify the build.gradle file to something like this.
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-SR3'}}Then, declare dependencies do not require a version number.
dependencies { compile 'org.springframework:spring-core'}Overwrite version number
Sometimes you may need to override the version number in Spring IO Platform and use the version number we specify ourselves instead. If using Maven, modify the version number in the properties node of the pom.xml file.
<properties> <foo.version>1.1.0.RELEASE</foo.version></properties>
If you use Gradle, add the ext attribute in build.gradle.
ext['foo.version'] = '1.1.0.RELEASE'
or
ext {foo.version = '1.1.0.RELEASE'}It can also be set in the gradle.properties file.
foo.version=1.1.0.RELEASE
Known issues
Due to the widespread use of Google Guava class libraries, there may be incompatibility when referencing different projects. At this time, we need to manually specify the appropriate version number to ensure that the project can run normally.
If you want to know more about the version number of Spring IO Platform, you can check the official documentation appendix.
Sample program
In fact, this article can end here, because Spring IO Platform does not actually have much to talk about.
Here is a small example of me, a Spring MVC program built with Spring IO Platform and Gradle. Below is the corresponding build.gradle file. You can see that since Spring IO Platform is used, all the dependencies here do not have a specified version number.
group 'yitian.study'version '1.0-SNAPSHOT'buildscript {repositories {jcenter()}dependencies {classpath 'io.spring.gradle:dependency-management-plugin:1.0.0.RELEASE'}}apply plugin: 'java'apply plugin: 'war'apply from: 'https://raw.github.com/akhikhl/gretty/master/pluginScripts/gretty.plugin'apply plugin: 'io.spring.dependency-management'sourceCompatibility = 1.8repositories { mavenCentral() jcenter()}dependencies {testCompile group: 'junit', name: 'junit' compile 'org.springframework:spring-webmvc' compile group: 'org.springframework.boot', name: 'spring-boot-starter-logging'}dependencyManagement {imports {mavenBom 'io.spring.platform:platform-bom:Brussels-SR3'}}From the IDE's prompt, you can see that all version numbers are correctly handled by Spring IO Platform.
The complete example is here, although I feel like most don't need to look at this.
Summarize
The above is all the brief introduction of Spring IO Platform in this article, I hope it will be helpful to everyone. Interested friends can continue to refer to other related topics on this site. If there are any shortcomings, please leave a message to point it out. Thank you friends for your support for this site!