BOM generation of all submodules in Gradle.
When you create a common use library, which consists of many sub modules (artifacts), you probably would like to generate a Maven BOM (Bill of Material) file, so that you can avoid version declaration duplication.
Doing it in Maven is quite straightforward, but in Gradle (as of today) it is not well documented and many Gradle based complex projects lack BOM file.
Fortunately Spring IO Dependency Management plugin helps us with doing that.
Let’s start with a simple Gradle based project with two submodules (client and server):
First you need to apply maven-publish
and io.spring.dependency-management
plugins. The first one will be responsible for BOM generation and the latter one will add a dependencyManagement
DSL to define versions of your modules.
|
|
To simplify project configuration, all projects have following configuration:
|
|
Then you need to declare versions of modules in dependencyMangement
section. We will add all gradle modules (subprojects) so that we are not forced to manually add each new module.
|
|
Then, all we need to do is to declare maven BOM generation using maven-publish
plugin’s DSL. We need to define mavenBom
empty publication (without additional artifacts defined).
|
|
Now, everything is done and we can test it:
|
|
In effect we have following BOM artifact generated:
|
|
I hope this going to help you create useful BOM files. Having BOM’s it is easier to keep track of project’s dependencies and to enforce consistent versioning across applications you create.