Using the Latest Spring Boot Release in Gradle

I’m using the latest Spring Boot Gradle Plugin in a new project (currently v1.2.3) and I noticed that the Spring Boot dependencies in my IntelliJ External Libraries list were of an earlier version, v1.1.4.

So I was wondering, why weren’t the Spring Boot dependencies the same as my plugin version, which I thought was the case by default?

The Spring Boot Plugin setup in my build.gradle was this.

buildscript {
    repositories { jcenter() }
    dependencies {
        classpath("org.springframework.boot:spring-boot-gradle-plugin:1.2.3.RELEASE")
    }
}

But my Spring Boot dependency libraries were version 1.1.4-RELEASE, not 1.2.3-RELEASE as you see below.

The spring-boot plugin registers a custom Gradle ResolutionStrategy with your build that allows you to omit version numbers when declaring dependencies to blessed artifacts. “Blessed artifacts,” I love that.

My problem was declaring a version of a Spring-Boot dependency in my build.gradle file, forcing Gradle to use the JARs for that dependency. Here was my slip-up:

dependencies {
    compile 'org.springframework.boot:spring-boot-starter-data-jpa:1.1.4.RELEASE'
    compile 'org.hibernate:hibernate-core:4.3.6.Final'
    compile 'javax.servlet:javax.servlet-api:3.1.0'

By explicitly using Spring-Boot-Starter-Data-JPA:1.1.4 I was requiring Gradle to use the Spring-Boot v1.1.4 library. The correct approach was

dependencies {
    compile 'org.springframework.boot:spring-boot-starter-data-jpa'
    compile 'org.hibernate:hibernate-core'
    compile 'javax.servlet:javax.servlet-api'

No version numbers, see? If you need to use an explicit dependency version or some other dependency not known to Spring Boot, simply add the version info as usual for that dependency.

So in conclusion, to make sure your version of Spring Boot is the same as your Spring Boot Gradle Plugin, don’t use version numbers for Spring Boot dependencies.