Sergey Tsypanov
Sergey Tsypanov

Reputation: 4370

Is there a way to use version of dependency declared in Spring Boot BOM

I have a Gradle-based project with root build.gradle declaring dependency on Spring Boot BOM:

ext {
  springBootVersion = '2.6.3'
}

subprojects {
  dependencies {
    implementation platform("org.springframework.boot:spring-boot-dependencies:$springBootVersion")
  }
}

then in a subproject I have dependencies on liquibase-core and liquibase-cdi:

ext {
  liquiBaseVersion = '4.4.3'
}

dependencies {
  runtimeOnly "org.liquibase:liquibase-cdi:$liquiBaseVersion"
  runtimeOnly "org.liquibase:liquibase-core"
}

the problem is that the version of liquibase-core is automatically picked up from Spring Boot BOM declared in root build.gradle, but liquibase-cdi is not specified in that BOM, so I have to declare its version explicitly (otherwise gradle build fails).

I'd like to use somehow the version of liquibase-core specified in Spring Boot BOM for liquibase-cdi like this can be done with Maven placeholder ${liquibase.version} referencing the property specified in <properties/> of parent pom.

Is there a way to do the same with Gradle?

Upvotes: 0

Views: 862

Answers (1)

Moritz Halbritter
Moritz Halbritter

Reputation: 21

You can use

dependencyManagement.importedProperties['spring.version']

to get for example the spring.version property which is managed via the Dependency Management Plugin.

See https://docs.spring.io/dependency-management-plugin/docs/current/reference/html/#accessing-properties for details.

You can also use the programmatic access to the dependency management to find the managed version of Liquibase:

def liquibaseVersion = managedVersions['org.liquibase:liquibase-core']

See https://docs.spring.io/dependency-management-plugin/docs/current/reference/html/#working-with-managed-versions-programmatic-access

Upvotes: 2

Related Questions