Thriving.dev Learning Resources for Software Architects and Engineers
Blog Post

Streamline Micronaut + Gradle Updates with Renovate (2/4)

Posted on Feb 7 3min read intermediate

TLDR: Renovate cannot automatically update Micronaut dependencies for gradle projects created via 'Launch' or CLI. The first solution (out of 3) is a workaround, adding a 'hint' to libs.versions.toml.

Problem Recap

As covered in detail in the first post of this series Renovate cannot resolve the packageName and datasource from the gradle.properties file.

Solution 1

IMO the first solution I found is closer to a workaround. Once understood, is actually pretty straightforward.

In a first effort refactored the gradle project to use a version catalog with libs.versions.toml file. Along with that, I deleted the gradle.properties file and defined the micronaut platform version in the toml file instead (ref):

[versions]
# note: the version named `micronaut` is picked up by the micronaut gradle plugin
micronaut = "4.3.0"

So far so good. The gradle project is fine, but still not renovated.

...now here's the trick. I added one additional line of code under the [libraries] section:

[libraries]
# note: the defined library 'micronaut-platform' is not referenced directly in any build.gradle(.kts)
#       but required for renovate to check and update micronaut.
micronaut = { module = "io.micronaut.platform:micronaut-platform", version.ref = "micronaut" }

It's an alias for the maven artifact "io.micronaut.platform:micronaut-platform", linked to the micronaut version via version.ref.

This library is not actually used in any build.gradle(.kts) file as a dependency, since the micronaut gradle plugin resolves all dependencies anyway.

But it allows Renovate to do its thing!

Example

Here's an adjusted starter project, originally created via 'Launch', with Renovate enabled:
https://github.com/thriving-dev/micronaut-gradle-renovate-example-1

The project is automatically kept up-to-date for minor and patch version updates, with automerge enabled.

Blog header image showing the logos of Micronaut, Gradle and Mend Renovate

Summary

  • Use gradle version catalog with libs.versions.toml, drop the gradle.properties
  • Define a version micronaut = "4.x.x"
  • Include an un-referenced libraries dependency on io.micronaut.platform:micronaut-platform with version.ref = "micronaut" to link to the micronaut version

Is This THE Best Solution?

When writing up this blog post I found three different solutions to the problem introduced.

Please continue with part 3!
-> 'Solution 2: Gradle Version Catalog (alternative via settings.gradle.kts) + Dependency Hint + MicronautExtension 'version<->libs' reference'.

Footnote: This blog post was written to work with Micronaut 4.x and Gradle 8.

Tip

If you're a maintainer or contributor to Open-Source Java libraries, take a look at thriving-dev/java-library-template introduced in September 2023. It ships with a ready to use renovate.json and setup guide.

CC BY-NC-SA 4.0 2022-2024 漏 Thriving.dev