Given a multi-project build that comprises a bunch of sub projects and a platform project (using Gradle’s java-platform
plugin), I realized that in most subprojects I need to repeatedly create platform dependencies
api platform(project(':my-platform'))
Quite often this also needs to be repeated for other configurations, which some of the subprojects define. All in all, this is quite verbose and gives raise to the question whether it can be simplified.
I thought about extracting/centralizing all those definitions into the root project and to create a platform dependency for all sub projects and for each configuration (since I cannot know the configurations a priori in the root project). Something like this:
// build.gradle of the root project
subprojects { // assuming we only have Java sub projects, otherwise we would filter here accordingly
dependencies {
configurations.each { add(it.name, platform(project(':my-platform'))) }
}
}
My question is whether this can be considered good practice? Any problems you are seeing with this approach?