#79 - Add Gradle configuration to the BOM example.

This commit is contained in:
Andy Wilkinson
2015-04-16 17:24:07 +01:00
committed by Oliver Gierke
parent 2c9f75c7e0
commit e1e22f4e5e
3 changed files with 65 additions and 19 deletions

View File

@@ -1,8 +1,10 @@
= Spring Data - Release Train BOM example
This project shows the usage of the Spring Data release train in a non-Spring-Boot project. It basically consists of the `pom.xml` with the following noteworthy sections:
This project shows the usage of the Spring Data release train in a non-Spring-Boot project with both Maven and Gradle.
- the `<properties />` element has properties for both the Spring and Spring Data. For Spring Framework we use a plain version, for Spring Data we name the release train release. The names for that follow the following convention:
== Properties
In both Maven and Gradle a couple of properties are used to define the versions of Spring Framework and Spring Data to use. For Spring Framework a plain version is used. For Spring Data we refer to a particular revision of a release train. The naming of Spring Data releases uses the following conventions:
** `${release-train}-M1` -> Milestones
** …
@@ -10,9 +12,21 @@ This project shows the usage of the Spring Data release train in a non-Spring-Bo
** …
** `${release-train}-RELEASE` -> GA version
** `${release-train}-SR1` -> Services release (bugfixes) for that release train
** …
- the `<dependencyManagement />` section now declares dependencies to the BOMs for both Spring and Spring Data, using the import scope and pom type.
- the standard `<dependencies />` section can now list Spring and Spring Data dependencies without declaring a version and still be sure all libraries are in matching versions.
== Maven
Note, that we don't declare a Spring dependency here. Declaring the BOM nonetheless makes sure we control the version of all transitive Spring dependencies pulled in by the Spring Data modules.
The `<dependencyManagement />` section declares dependencies to the BOMs for both Spring and Spring Data, using the `import` scope and `pom` type.
The standard `<dependencies />` section can now list Spring Framework and Spring Data dependencies without declaring a version and still be sure all libraries are in matching versions.
Note, that we don't declare a Spring Framework dependency here. The import of the Spring Framework BOM nonetheless makes sure we control the version of all transitive Spring Framework dependencies pulled in by the Spring Data modules.
== Gradle
Gradle does not support Maven BOMs out of the box so the first thing to do is to declare a buildscript dependency on the https://github.com/spring-gradle-plugins/dependency-management-plugin[dependency management plugin] and apply it to the project.
With the plugin applied, the `dependencyManagement` section can be used to import the Spring Framework and Spring Data BOMs.
The standard `dependencies` section can now list Spring and Spring Data dependencies without declaring a version and still be sure all libraries are in matching versions.
Note, that we don't declare a Spring Framework dependency here. The dependency management plugin and Spring Framework BOM nonetheless makes sure we control the version of all transitive Spring Framework dependencies pulled in by the Spring Data modules.

32
bom/build.gradle Normal file
View File

@@ -0,0 +1,32 @@
buildscript {
repositories {
jcenter()
}
dependencies {
classpath 'io.spring.gradle:dependency-management-plugin:0.5.0.RELEASE'
}
}
apply plugin: 'io.spring.dependency-management'
apply plugin: 'java'
ext {
springVersion = '4.1.6.RELEASE'
springDataVersion = 'Fowler-RELEASE'
}
repositories {
jcenter()
}
dependencyManagement {
imports {
mavenBom "org.springframework:spring-framework-bom:${springVersion}"
mavenBom "org.springframework.data:spring-data-releasetrain:${springDataVersion}"
}
}
dependencies {
compile 'org.springframework.data:spring-data-rest-webmvc'
compile 'org.springframework.data:spring-data-mongodb'
}

View File

@@ -5,17 +5,17 @@
<groupId>org.springframework.data.examples</groupId>
<artifactId>spring-data-examples-bom</artifactId>
<version>1.0.0.BUILD-SNAPSHOT</version>
<name>Spring Data - Using the BOM for dependency management</name>
<properties>
<spring.version>4.1.6.RELEASE</spring.version>
<spring-data.version>Fowler-RELEASE</spring-data.version>
</properties>
<dependencyManagement>
<dependencies>
<dependency>
<groupId>org.springframework</groupId>
<artifactId>spring-framework-bom</artifactId>
@@ -23,7 +23,7 @@
<scope>import</scope>
<type>pom</type>
</dependency>
<dependency>
<groupId>org.springframework.data</groupId>
<artifactId>spring-data-releasetrain</artifactId>
@@ -31,23 +31,23 @@
<scope>import</scope>
<type>pom</type>
</dependency>
</dependencies>
</dependencyManagement>
<dependencies>
<dependency>
<groupId>org.springframework.data</groupId>
<artifactId>spring-data-rest-webmvc</artifactId>
</dependency>
<dependency>
<groupId>org.springframework.data</groupId>
<artifactId>spring-data-mongodb</artifactId>
</dependency>
</dependencies>
</project>
</project>