spring-gradle-plugins / dependency-management-plugin

A Gradle plugin that provides Maven-like dependency management functionality
684 stars 85 forks source link

dependencyManagement.importedProperties is empty #346

Closed micheljung closed 1 year ago

micheljung commented 1 year ago

According to Accessing Properties from Imported Boms, version properties can be accessed like so:

dependencyManagement.importedProperties["spring.version"]

However, dependencyManagement.importedProperties is empty.

plugins {
  id("io.spring.dependency-management") version "1.1.0"
}

println(dependencyManagement.importedProperties)
println(dependencyManagement.importedProperties["spring.version"])

Output:

{}
null
wilkinsona commented 1 year ago

With the snippet above, I would not expect there to be any imported properties as no boms have been imported. Do you see the problem when a bom is imported?

micheljung commented 1 year ago

You're right:

plugins {
  id("io.spring.dependency-management") version "1.1.0"
}

dependencyManagement {
  imports {
    mavenBom("io.spring.platform:platform-bom:Cairo-SR8")
    // This does not specify spring.version
    // mavenBom("org.springframework.boot:spring-boot-dependencies:3.0.1")
  }
}

println(dependencyManagement.importedProperties["spring.version"])
5.0.13.RELEASE

But this shouldn't be necessary, should it?

When the io.spring.dependency-management plugin is applied to a project, the Spring Boot plugin will automatically import the spring-boot-dependencies bom.

https://docs.spring.io/spring-boot/docs/current/gradle-plugin/reference/htmlsingle/#reacting-to-other-plugins.dependency-management

And if we needed to import the Bom explicitly, how can we make sure we import a Version that is compatible with io.spring.dependency-management?

wilkinsona commented 1 year ago

You haven't applied the Spring Boot plugin so how it reacts to other plugins being applied does not matter. If you apply both the Spring Boot plugin and the dependency management plugin, Boot's plugin will automatically import the spring-boot-dependencies bom and its imported properties will be available:

plugins {
  id("io.spring.dependency-management") version "1.1.0"
  id("org.springframework.boot") version "3.0.1"
}

repositories {
  mavenCentral()
}

println(dependencyManagement.importedProperties["spring-framework.version"])

The above will output 6.0.3.

And if we needed to import the Bom explicitly, how can we make sure we import a Version that is compatible with io.spring.dependency-management?

The io.spring.dependency-management plugin should support any valid Maven bom.