Spring IO Platform is primarily intended to be used with a dependency management system. It works well with both Maven and Gradle.
The Platform uses Maven’s support for dependency management to provide dependency versions to your application’s build. To consume this dependency management you can import the Platform’s pom into your application’s pom:
<?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>1.1.1.RELEASE</version> <type>pom</type> <scope>import</scope> </dependency> </dependencies> </dependencyManagement> … </project>
Alternatively, rather than importing the Platform’s pom, you may prefer to use it as your pom’s 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>1.1.1.RELEASE</version> <relativePath/> </parent> … </project>
Taking this approach, in addition to the dependency management that importing the pom provides, your
application will also gain some plugin management that provides sensible defaults for a number of
plugins, including Spring Boot’s Maven Plugin. To take advantage of
this default configuration, all you then need to do is to include the plugin in the <plugins>
section of your pom:
<build> <plugins> <plugin> <groupId>org.springframework.boot</groupId> <artifactId>spring-boot-maven-plugin</artifactId> </plugin> </plugins> </build>
If you want to use the Platform and Spring Boot together, you don’t have to use the Platform’s pom as the parent. Instead, you can import the Platform’s pom as described above and then perform the rest of the configuration manually. Spring Boot’s documentation on using it with Maven will show you how.
Whichever approach you choose, no dependencies will be added to your application. However, when you do declare a dependency on something that’s part of the Platform, you will now be able to omit the version number. For example:
<dependencies> <dependency> <groupId>org.springframework</groupId> <artifactId>spring-core</artifactId> </dependency> </dependencies>
For more details of what’s included in the Platform and the versions that are provided, please refer to the appendix.
To use the Platform with Gradle, you can use the Gradle Dependency Management Plugin and import the bom in much the same way as you would with Maven. The use of a plugin is necessary as Gradle does not provide an equivalent of Maven’s built-in dependency management support.
To use the plugin, you configure your build to apply the plugin and then in the
dependencyManagement
configuration you import the Platform’s bom:
buildscript { repositories { jcenter() } dependencies { classpath 'io.spring.gradle:dependency-management-plugin:0.3.0.RELEASE' } } apply plugin: 'io.spring.dependency-management' repositories { mavenCentral() } dependencyManagement { imports { mavenBom 'io.spring.platform:platform-bom:1.1.1.RELEASE' } }
With this configuration in place you can then declare a dependency on an artifact that’s part of the Platform without specifying a version:
dependencies {
compile 'org.springframework:spring-core'
}
For more details of what’s included in the Platform and the versions that are provided, please refer to the appendix.