spring-bootgradlespring-boot-gradle-plugin

How to get a spring boot dependency version in Gradle?


Having plugin disabled

plugins {
  id 'org.springframework.boot' version '2.7.9' apply false
}

And imported BOM manually, I want to get version in dependencies

subprojects {
  dependencyManagement {
    imports {
      mavenBom SpringBootPlugin.BOM_COORDINATES
    }
  }
  dependencies {
    //here I need version 
    implementation "org.slf4j:slf4j-api${???}"
  }
}

It's known from the documentation:

The spring-boot-dependencies bom that is automatically imported when the dependency management plugin is applied uses properties to control the versions of the dependencies that it manages. Browse the Dependency versions Appendix in the Spring Boot reference for a complete list of these properties.

To customize a managed version you set its corresponding property. For example, to customize the version of SLF4J which is controlled by the slf4j.version property:

ext['slf4j.version'] = '1.7.20'

But it's not know how to get one


Solution

  • Like this:

    dependencies {
      implementation "org.slf4j:slf4j-api:${dependencyManagement.managedVersions["org.slf4j:slf4j-api"]}"
    }
    

    Referent example in SB project