3

I have a Gradle setup where I currently need to hard code the spring-boot version. Is it possible to do this with dependency management instead? The issue occurs in my project module that contains the actual code. There I need a call to :

springBoot {
    requiresUnpack = ["com.example:util"]
}

In order to do that I need to apply the spring-boot plugin. For that plugin to be available I need to have a dependency to "org.springframework.boot:spring-boot-gradle-plugin:${springBootVersion}". And for that I need to specify the springBootVersion hard coded...

This is my parent gradle file:

buildscript {

    ext {
        springBootVersion = '1.4.0.RELEASE'
    }
    repositories {
        mavenCentral()
        jcenter()
    }
    dependencies {
        classpath "org.springframework.boot:spring-boot-gradle-plugin:${springBootVersion}"
        classpath 'io.spring.gradle:dependency-management-plugin:0.6.0.RELEASE'
    }
}

plugins {
    id "io.spring.dependency-management" version "0.6.0.RELEASE"
}

group 'test'


repositories {
    mavenCentral()
}

allprojects {
    apply plugin: 'java'
    apply plugin: 'io.spring.dependency-management'

    dependencyManagement {
        imports {
            // Note that these two BOM's are not always easy to combine, always define cloud first and try to find versions with same version of spring-boot when upgrading.
            mavenBom 'org.springframework.cloud:spring-cloud-starter-parent:Brixton.SR5'
            mavenBom 'io.spring.platform:platform-bom:2.0.7.RELEASE'

        }
    }
}

and this is my module gradle file:

group = "test"

apply plugin: 'spring-boot'
apply plugin: 'io.spring.dependency-management'

sourceCompatibility = 1.8
targetCompatibility = 1.8

// Temporary fix for jersey
springBoot {
    requiresUnpack = ["com.example:util"]
}

If I remove the dependency to spring-boot-gradle-plugin in parent gradle file, then I cannot use the apply plugin: 'spring-boot' in the module gradle file and without that the gradle DLS method springBoot { is not defined...

Can I achieve this without having to hard code springBootVersion = '1.4.0.RELEASE'in my parent gradle file?

Andreas Lundgren
  • 12,043
  • 3
  • 22
  • 44
  • I think it's actually a good question but you should be more precise on what you expect instead. From my point view, when you use such a dependency, I'd rather have the extact version of the dependency (even if I have to "hard code" it) so that the integrety of the all project is garanteed. It's like saying your application has to be deployed on Tomcat 7 for instance instead of "the latest version of Tomcat". You may not be sure what impacts will imply the change of the version. – Mickael Aug 29 '16 at 09:02
  • I think that by having specified a particular version of spring io.platform, I do have a specific version of spring boot specified. This version should also have been "tested" along with all the other dependencies defined in the spring io.platform BOM. But by also having to specify a version of spring boot directly, I may get conflicting versions of spring boot, or I need to upgrade the spring boot version in two places. Each time I upgrade spring io.platform, I need to remember to upgrade the hard chief spring boot version too... – Andreas Lundgren Aug 31 '16 at 07:17
  • I think the general question, which is as far as I can tell is still not answered, is how to avoid specifying the version of the Spring Boot Gradle plugin when also using Spring IO Platform's dependency management (which should be what determines the version of Spring Boot). In fact, there's an open issue: https://github.com/spring-io/platform/issues/328 for this. – Richard Steele Dec 04 '17 at 20:16

0 Answers0