Applying a (BOM-) platform to all configurations

I have some multi-project builds where everything should use the same versions of dependencies.

Currently the following works for libraries:

def somePlatform = enforcedPlatform("some-group:some-bom:${platformVersion}")
api(somePlatform)
annotationProcessor(somePlatform)
testAnnotationProcessor(somePlatform)

and for applications:

def somePlatform = enforcedPlatform("some-group:some-bom:${platformVersion}")
implementation(somePlatform)
annotationProcessor(somePlatform)
testAnnotationProcessor(somePlatform)

Ideally I’d like something like

subprojects {
  dependencies {
    all(enforcedPlatform("some-group:some-bom:${platformVersion}"))
  }
}

but I can see how that would not fly for a lot of builds out there.

One of my issues it that I can’t handle libraries (where I need to apply it to api) and applications (where I need to apply it to implementation) uniformly.

What would be the best way to DRY this code up a bit?

1 Like

Have been looking for the same, specifically for immutables. For debatable reasons, I’d rather avoid using version number properties, but so far that’s the only alternative I know of to

        implementation platform("org.immutables:value:2.8.1")
        annotationProcessor platform("org.immutables:value:2.8.1")
        testAnnotationProcessor platform("org.immutables:value:2.8.1")

If you explicitly depend on the platform in all your projects anyway, it should be fine to also use implementation for the libraries, no? (assuming you do not publish them to be consumed by other projects)