1

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

Artem Ptushkin
  • 1,151
  • 9
  • 17

2 Answers2

1

Like this:

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

Referent example in SB project

Artem Ptushkin
  • 1,151
  • 9
  • 17
0

I know my answer is slightly related to the question but for those who looking for io.spring.dependency-management usages be aware - the way this plugin works is not the same as Maven's <dependencyManagement>

It can downgrade transitive runtime dependencies and cause hard to detect runtime bugs. In my case the transitive runtime dependency on jakarta.json:jakarta.json-api was downgraded from 2.x to 1.x.

The more encouraged approach, which by the way works exactly the same as <dependencyManagement> is using Gradle platform dependency like so:

dependencies {
    implementation platform('org.springframework.boot:spring-boot-dependencies:<Boot version here>')

    // no need to specify versions here!
    implementation 'org.slf4j:slf4j-api'

}

The only downside of this approach is that you will need to specify Spring Boot version twice if you using org.springframework.boot Gradle plugin - in plugins block and in dependencies.

RomanMitasov
  • 925
  • 9
  • 25
  • 1
    sure it does, I was searching for an option without BOM, just a generic "GET version" any where in Gradle scripts – Artem Ptushkin Mar 07 '23 at 15:17
  • I've just found out another Gradle feature that seems relevant - [version catalogs](https://docs.gradle.org/current/userguide/platforms.html#sub:central-declaration-of-dependencies). They are specifically designed for cases where you need to use versions in Gradle scripts, not just declare dependencies. I don't know if such a catalog exists for Spring or not. – RomanMitasov May 03 '23 at 06:52