Skip to content

Commit e1e22f4

Browse files
wilkinsonaodrotbohm
authored andcommitted
spring-projects#79 - Add Gradle configuration to the BOM example.
1 parent 2c9f75c commit e1e22f4

File tree

3 files changed

+65
-19
lines changed

3 files changed

+65
-19
lines changed

bom/README.adoc

Lines changed: 20 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,18 +1,32 @@
11
= Spring Data - Release Train BOM example
22

3-
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:
3+
This project shows the usage of the Spring Data release train in a non-Spring-Boot project with both Maven and Gradle.
44

5-
- 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:
5+
== Properties
6+
7+
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:
68

79
** `${release-train}-M1` -> Milestones
810
** …
911
** `${release-train}-RC1` -> Release candidate
1012
** …
1113
** `${release-train}-RELEASE` -> GA version
1214
** `${release-train}-SR1` -> Services release (bugfixes) for that release train
13-
**
1415

15-
- the `<dependencyManagement />` section now declares dependencies to the BOMs for both Spring and Spring Data, using the import scope and pom type.
16-
- 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.
16+
== Maven
17+
18+
The `<dependencyManagement />` section declares dependencies to the BOMs for both Spring and Spring Data, using the `import` scope and `pom` type.
19+
20+
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.
21+
22+
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.
23+
24+
== Gradle
25+
26+
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.
27+
28+
With the plugin applied, the `dependencyManagement` section can be used to import the Spring Framework and Spring Data BOMs.
29+
30+
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.
1731

18-
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.
32+
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.

bom/build.gradle

Lines changed: 32 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,32 @@
1+
buildscript {
2+
repositories {
3+
jcenter()
4+
}
5+
dependencies {
6+
classpath 'io.spring.gradle:dependency-management-plugin:0.5.0.RELEASE'
7+
}
8+
}
9+
10+
apply plugin: 'io.spring.dependency-management'
11+
apply plugin: 'java'
12+
13+
ext {
14+
springVersion = '4.1.6.RELEASE'
15+
springDataVersion = 'Fowler-RELEASE'
16+
}
17+
18+
repositories {
19+
jcenter()
20+
}
21+
22+
dependencyManagement {
23+
imports {
24+
mavenBom "org.springframework:spring-framework-bom:${springVersion}"
25+
mavenBom "org.springframework.data:spring-data-releasetrain:${springDataVersion}"
26+
}
27+
}
28+
29+
dependencies {
30+
compile 'org.springframework.data:spring-data-rest-webmvc'
31+
compile 'org.springframework.data:spring-data-mongodb'
32+
}

bom/pom.xml

Lines changed: 13 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -5,49 +5,49 @@
55
<groupId>org.springframework.data.examples</groupId>
66
<artifactId>spring-data-examples-bom</artifactId>
77
<version>1.0.0.BUILD-SNAPSHOT</version>
8-
8+
99
<name>Spring Data - Using the BOM for dependency management</name>
10-
10+
1111
<properties>
1212
<spring.version>4.1.6.RELEASE</spring.version>
1313
<spring-data.version>Fowler-RELEASE</spring-data.version>
1414
</properties>
15-
15+
1616
<dependencyManagement>
1717
<dependencies>
18-
18+
1919
<dependency>
2020
<groupId>org.springframework</groupId>
2121
<artifactId>spring-framework-bom</artifactId>
2222
<version>${spring.version}</version>
2323
<scope>import</scope>
2424
<type>pom</type>
2525
</dependency>
26-
26+
2727
<dependency>
2828
<groupId>org.springframework.data</groupId>
2929
<artifactId>spring-data-releasetrain</artifactId>
3030
<version>${spring-data.version}</version>
3131
<scope>import</scope>
3232
<type>pom</type>
3333
</dependency>
34-
34+
3535
</dependencies>
36-
36+
3737
</dependencyManagement>
38-
38+
3939
<dependencies>
40-
40+
4141
<dependency>
4242
<groupId>org.springframework.data</groupId>
4343
<artifactId>spring-data-rest-webmvc</artifactId>
4444
</dependency>
45-
45+
4646
<dependency>
4747
<groupId>org.springframework.data</groupId>
4848
<artifactId>spring-data-mongodb</artifactId>
4949
</dependency>
50-
50+
5151
</dependencies>
52-
53-
</project>
52+
53+
</project>

0 commit comments

Comments
 (0)