0
votes

I'm using the Spring Boot framework with Gradle. I know that to include some Spring dependencies I can reference "starters" without explicitly defining the version; the version will be controlled by that version of Spring Boot I choose, which is the version of the Spring Boot Gradle plugin. Example (non-relevant Gradle code is omitted):

buildscript {
    repositories {
        mavenCentral()
    }

    dependencies {
        classpath group: 'org.springframework.boot', name: 'spring-boot-gradle-plugin', version: BOOT_VERSION
        classpath group: 'io.spring.gradle', name: 'dependency-management-plugin', version: DEP_MGMT_VERSION
    }
}

...

dependencies {
    compile 'org.springframework.boot:spring-boot'
    testCompile 'org.springframework.boot:spring-boot-starter-test'
}

Notice above that there are no explicit versions defined my for my application dependencies.

Now, let's say I want to include some Spring Cloud and Spring Integration dependencies. For example:

compile 'org.springframework.integration:spring-integration-mqtt:some-version'
compile 'org.springframework.cloud:spring-cloud-netflix-eureka-server:some-other-version'

How can I ensure that the versions I use for those dependencies are compatible with my other Spring Boot dependencies? I cannot leave out the version, so it seems the Gradle plugin is not taking care of these dependencies (maybe it only takes care of those with group org.springframework.boot?).

To put it another way, is there a clean, safe method to ensure that all my Spring dependencies will work together, from Spring Boot, Spring Cloud etc.?

1

1 Answers

0
votes

Use the starters in your gradle script.

dependencies {
    compile("org.springframework.boot:spring-boot-starter-web:2.0.0.RELEASE")
    compile ':spring-cloud-starter-config'
    compile ':spring-cloud-starter-netflix-eureka-client'
    compile ':spring-boot-starter-integration'
}

https://github.com/spring-gradle-plugins/dependency-management-plugin/blob/master/README.md

For Spring Cloud, add a dependencyManagement section with the compatible Cloud-to-Boot versions. The documentation indicates which project versions are compatible with the corresponding Boot trains (1.4.x, 1.5.x, 2.x):

dependencyManagement {
  imports {
    mavenBom ':spring-cloud-dependencies:Finchley.M8'
  }
}

Finchley builds and works with Spring Boot 2.0.x, and is not expected to work with Spring Boot 1.5.x.

The Dalston and Edgware release trains build on Spring Boot 1.5.x, and are not expected to work with Spring Boot 2.0.x.

The Camden release train builds on Spring Boot 1.4.x, but is also tested with 1.5.x.

http://projects.spring.io/spring-cloud/