Using the Spring Dependency Management Gradle Plugin

We recently upgraded NixMash Spring from Spring Boot 1.3.5 to 1.4, so we were up to our eyeballs in dependency issues. It was a good time to go deep with the Spring Dependency Management Gradle Plugin. Here is the plugin’s home on GitHub with an excellent

For Spring Boot 1.3 and higher, ignore the following section on adding the plugin, as it is now included in the Spring Boot Gradle Plugin.

You can add the plugin a couple of ways in Gradle. Here is how we added it to the NixMash Spring root build.gradle file, that is, before realizing it was included in Spring Boot 1.4. (1) Add the Dependency to the Build Script and (2) apply the plugin.

Specifying a Spring Dependency Package Version

We had issues with Hibernate 5 and Spring Boot 1.4 so we downgraded to Hibernate 4.3 by adding the following to our build.gradle as suggested in the Spring Boot 1.4 Release Notes.

ext['hibernate.version'] = '4.3.11.Final'

Here are the resulting hibernate-core and hibernate-entitymanager dependencies in our Spring Boot 1.4 application.

Specifying a Spring Boot Starter Version

In this example we’re going to change the default version of the Velocity Starter package from 1.4.0 to 1.3.7.

With the following result.

Specifying a Spring Project Release

You won’t find the above example in the NixMash Spring Repository (we’re using the Velocity 1.4.0 Starter until we can replace Velocity, now @Deprecated, with FreeMarker). You WILL find the following example in NixMash Spring, however.

Let’s say Rob Winch of the Spring Development Team releases a new version of Spring Security like he did recently with 4.1.3. The version of Spring Security bundled with Spring Boot 1.4.0 is 4.1.1.RELEASE.

ext['spring-security.version'] = '4.1.3.RELEASE'

The results are shown below. How did I know to use “spring-security.version”? Because it’s in the Spring Boot Dependencies POM.  Gold, Jerry! Gold!

We could also upgrade select libraries by creating a Dependency Set.

Source Code Notes for this Post

All source code discussed in this post can be found in my NixMash Spring GitHub repo and viewed online here.