spring-gradle-plugins / dependency-management-plugin

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

Is there a way to create and use "effective BOMs"? #367

Closed oliveryasuna closed 9 months ago

oliveryasuna commented 9 months ago

In Gradle, we can create bundles. For example:

val slf4jVersion = "1.7.32"
library("org.slf4j.slf4j-api", "org.slf4j:slf4j-api:${slf4jVersion}")
library("org.slf4j.jcl-over-slf4j", "org.slf4j:jcl-over-slf4j:${slf4jVersion}")
library("org.slf4j.jul-to-slf4j", "org.slf4j:jul-to-slf4j:${slf4jVersion}")
library("org.slf4j.slf4j-simple", "org.slf4j:slf4j-simple:${slf4jVersion}")
bundle("org.slf4j.all", listOf("org.slf4j.slf4j-api", "org.slf4j.jcl-over-slf4j", "org.slf4j.jul-to-slf4j", "org.slf4j.slf4j-simple"))

Can we do something similar that specifies multiple versions, like a BOM would. Something like:

val slf4jVersion = "1.7.32"
library("org.slf4j.slf4j-api", "org.slf4j:slf4j-api:${slf4jVersion}")
library("org.slf4j.jcl-over-slf4j", "org.slf4j:jcl-over-slf4j:${slf4jVersion}")
library("org.slf4j.jul-to-slf4j", "org.slf4j:jul-to-slf4j:${slf4jVersion}")
library("org.slf4j.slf4j-simple", "org.slf4j:slf4j-simple:${slf4jVersion}")
effectiveBom("org.slf4j.all", listOf("org.slf4j.slf4j-api", "org.slf4j.jcl-over-slf4j", "org.slf4j.jul-to-slf4j", "org.slf4j.slf4j-simple"))

// Use it later.
mavenBom("org.slf4j.all")
wilkinsona commented 9 months ago

The documentation describes how to declare dependency management where there's no existing bom provided. Your example above would look something like this:

dependencyManagement {
     dependencies {
          dependencySet(group:'org.slf4j', version: '1.7.32') {
               entry 'slf4j-api'
               entry 'jcl-over-slf4j'
               entry 'jul-to-slf4j'
               entry 'slf4j-simple'
          }
     }
}

This declares and applies the dependency management at the same time. There is no support for declaring dependency management and then applying it later.

oliveryasuna commented 9 months ago

@wilkinsona Thank you!