How to Manage Versions using Maven BOM, Gradle and GitHub

Vladimír Oraný
Stories by Agorapulse
3 min readDec 3, 2019

I have noticed that many great frameworks such as Spring Boot, Grails or Micronaut are using Maven bill-of-material (BOM) to manage versions of their dependencies aligned. Using BOM you can constraint the versions of transitive dependencies as well as it allows you to specify just the group and name of the module ane let the version be determined by BOM.

I wanted to bring the same smooth versions' management into our project so I've created a seed project to generate the BOM files easily. Although there is a java-platform Gradle plugin which is designed for generating BOM files I got inspired by the approach taken by Micronaut team and created a project which generated the BOM from a simple properties file and publishes it into GitHub Maven repository using GitHub Actions.

Creating BOM

You can use the seed project to easily create your own BOM file. The project follows very simple conventions:

  1. (optionally) declare versions placeholders such as groovy.version in file src/main/versions/_versions.properties
  2. declare desired module version in a file src/main/versions/<groupId>.properties (for example src/main/versions/org.codehaus.groovy.properties) either explicitly such as groovy = 2.5.4 or using the placeholder defined before groovy = groovy.version
  3. create a release on GitHub or just push a tag to the repository to release a new version of the BOM

Once the GitHub Action is triggered by the new tag and when it is finished then the BOM will be available at https://maven.pkg.github.com/<your org>/<your repo>.

Please, follow the documentation for a further reference.

Using BOM

To use the generated BOM you have to add the following lines into your Gradle build:

repositories {
maven { url 'https://maven.pkg.github.com/<repo>/<org>' }
}
dependencies {
compile platform('<your group id>:<your bom name>:<version>')
// some dependency declared in the BOM
compile 'org.codehaus.groovy:groovy'
}

If you are still using an older version of Gradle you can also use the Spring dependency plugin:

depedencyManagement {
imports {
mavenBom '<your group id>:<your bom name>:<version>'
}
}

--

--