If I have an included java-platform
build (e.g. ‘./platform/build.gradle.kts’) for my root project (‘./build.gradle.kts’), and that platform depends on a third-party Maven BOM (e.g. “org.springframework.boot:spring-boot-dependencies”), does it makes sense to declare a ComponentMetadataRule
to align the versions of that imported BOM in my included and consumed platform, or do I need to apply the rule to the root project?
It’d be handy if I could do it once in the platform, and have it apply to all projects that consume that platform.
For example…
‘platform/build.gradle.kts’:
plugins {
`java-platform`
}
javaPlatform {
allowDependencies()
}
dependencies {
components.all<SpringBomAlignmentRule>()
api(platform("org.springframework.boot:spring-boot-dependencies:3.0.3"))
}
abstract class SpringBomAlignmentRule : ComponentMetadataRule {
override fun execute(ctx: ComponentMetadataContext) {
ctx.details.run {
when (id.group) {
"org.springframework" ->
belongsTo(
"org.springframework:spring-framework-bom:${id.version}",
false
)
"org.springframework.boot" ->
belongsTo(
"org.springframework.boot:spring-boot-dependencies:${id.version}",
false
)
}
}
}
}