We use a BOM to share our dependency management in MyCompany.
It is defined as a Maven POM. Here is a minimal example:
<?xml version="1.0" encoding="UTF-8"?>
<project>
<modelVersion>4.0.0</modelVersion>
<groupId>com.mycompany.common</groupId>
<artifactId>common-java</artifactId>
<version>1.0.0</version>
<packaging>pom</packaging>
<properties>
<spring-boot.version>2.4.0</spring-boot.version>
</properties>
<dependencyManagement>
<dependencies>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-dependencies</artifactId>
<version>${spring-boot.version}</version>
<type>pom</type>
<scope>import</scope>
</dependency>
</dependencies>
</dependencyManagement>
</project>
It is then used from Gradle projects.
Although this works for code dependencies, I'd like to find out a way to use it from plugin management.
For now, we define in settings.gradle.kts
:
pluginManagement {
val springBootVersion: String by settings
plugins {
id("org.springframework.boot") version(springBootVersion)
}
}
springBootVersion
being defined in the gradle.properties
.
This is an issue to me because Spring version is defined both:
- in the shared BOM;
- in each project's plugin management.
How can I access to that BOM from Gradle's plugin management? And if I can't, what is a good don't-repeat-yourself practice to do so?
Your custom platform can provide an opinion about which version of the Spring Boot Gradle plugin you want clients to use (especially since it's not included in the
spring-boot-dependencies
BOM).Here are the relevant parts of an example platform's
build.gradle.kts
file, for example:That will generate a BOM that aligns both
spring-boot-gradle-plugin
andspring-boot-dependencies
:Your client projects can then just depend upon your platform and inherit its opinion about the Spring Boot version using something like this:
buildSrc/build.gradle.kts
:build.gradle.kts
:Of course, you could also use Gradle version catalogs to centralize versions, which are inlined for clarity in the examples.