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

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

Posted on Feb 8 3min read intermediate

TLDR: Renovate cannot automatically update Micronaut dependencies for gradle projects created via 'Launch' or CLI. The second solution (out of 3) is another workaround, using a version reference from settings.gradke(.kts) in the micronaut gradle plugin 'MicronautExtension'.

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 2

The second solution is similar to solution 1. Since we're all busy developers, I'll keep this part short and concise to avoid repetition.

Same as before, I have refactored the gradle project to use a version catalog - but this time using the script style -> via the settings.gradle(.kts) instead of a libs.versions.toml file. Along with that, same as before, remember to delete the gradle.properties file.

Here's the content of the settings.gradle(.kts) file:

rootProject.name = "micronaut-gradle-renovate-example-2"

dependencyResolutionManagement {
    versionCatalogs {
        create("libs") {
            plugin("johnrengelman-shadow", "com.github.johnrengelman.shadow").version("8.1.1")
            plugin("micronaut-application", "io.micronaut.application").version("4.3.2")
            plugin("micronaut-aot", "io.micronaut.aot").version("4.3.2")

            library("micronaut-platform", "io.micronaut.platform:micronaut-platform:4.3.0")
            library("junit", "org.junit.jupiter:junit-jupiter:5.10.2")
            library("assertj", "org.assertj:assertj-core:3.25.3")
            library("testcontainers", "org.testcontainers:testcontainers:1.19.4")
            library("testcontainers-junit5", "org.testcontainers:junit-jupiter:1.19.4")

            bundle("testcontainers-junit", listOf("testcontainers", "testcontainers-junit5"))
        }
    }
}

As with the first solution, I want to point out the additional dependency added (compared to the original Micronaut starter template):

library("micronaut-platform", "io.micronaut.platform:micronaut-platform:4.2.3")

In contrary to how this works with the .toml file, the version now needs to be defined as part of the build.gradle(.kts):

micronaut {
    version("4.2.3")
    // ...
}

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

...and here's the new trick: Instead of setting a static version, we simply reference the version of the library mentioned above!!

micronaut {
    /*
    reference to the version catalog instead of using a static version string -> `version("4.2.1")`
    or via gradle.properties as used by default 'Micronaut Launch'.
    The version defined here is ignored by renovate but actually used to determine all micronaut dependencies
    */
    version(libs.micronaut.platform.get().version)
    
    // ...
    
}

=> Renovate tracks and updates the micronaut-platform dependency which is consecutively used in the MavenExtension of the Micronaut Gradle Plugin!

Example

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

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

Summary

  • Use gradle version catalog with settings.gradle(.kts), drop the gradle.properties
  • Include a dependency library("micronaut-platform", "io.micronaut.platform:micronaut-platform:4.x.x") to the version catalog
  • Set the version for the MicronautExtension using a reference to the library -> version(libs.micronaut.platform.get().version) <- in the build.gradle(.kts)

So, Is THIS The Best Solution?

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

Please continue with part 4!
-> '馃 Solution 3: Renovate Custom Regex Manager!'.

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