Spring Modulith 2.1

When upgrading to Spring Modulith 2.1, refer to the Spring Modulith 2.1.0 Release Notes for newly introduced APIs, deprecated APIs, and breaking changes. Spring Modulith 2.1 is the release line for Spring Boot 4.1, and the Spring Boot 4.1 upgrade recipe chains this recipe.

The io.arconia.rewrite.spring.modulith2.UpgradeSpringModulith_2_1 recipe automates most of the changes introduced in Spring Modulith 2.1. You can use it to update your project to the latest Spring Modulith 2.1.x release.

The recipe will:

  • Upgrade all org.springframework.modulith dependencies to the 2.1.x release line.

  • Rename Spring Modulith configuration properties that were deprecated with a replacement, including the misspelled spring.modulith.events.staleness.check-intervall key, which was the only spelling available in 2.1.0 and is corrected to check-interval.

  • Move a direct dependency on spring-modulith-observability to spring-modulith-observability-core, since the observability support was split into an API and a core artifact and the original artifact no longer ships any classes.

  • Relocate the public observability types ModulithContext, ModulithObservationConvention, ObservedModule, and ObservedModuleType from the support package to the org.springframework.modulith.observability package.

  • Replace calls to the deprecated PublishedEventAssert.matching(Function, Object) with matchingValue(Function, Object), since the deprecated method is removed in Spring Modulith 2.2. Calls passing a Predicate keep using matching.

See its entry in the Recipe Catalog for the full list of recipes this upgrade applies, each with its options and a before/after example.

Run the Recipe

You can apply this recipe with any OpenRewrite-compatible tool. The tabs below show three of them: the Arconia CLI, the OpenRewrite Gradle plugin, and the OpenRewrite Maven plugin. See Running Recipes for a comparison of when to pick each one.

  • Arconia CLI

  • Gradle

  • Maven

arconia rewrite run --recipe-name io.arconia.rewrite.spring.modulith2.UpgradeSpringModulith_2_1

First, create an init.gradle file in your project root with the following content.

initscript {
    repositories {
        gradlePluginPortal()
    }
    dependencies {
        classpath("org.openrewrite:plugin:latest.release")
    }
}

rootProject {
    plugins.apply(org.openrewrite.gradle.RewritePlugin)
    dependencies {
        rewrite("io.arconia.migrations:rewrite-spring:latest.release")
    }

    // Remove when project repositories are disabled
    afterEvaluate {
        if (repositories.isEmpty()) {
            repositories {
                mavenCentral()
            }
        }
    }

    configurations.named("rewrite") {
        canBeConsumed = false
    }
}

Then, run the following command.

./gradlew rewriteRun \
    --init-script init.gradle \
    --no-parallel \
    -DactiveRecipe=io.arconia.rewrite.spring.modulith2.UpgradeSpringModulith_2_1

You can remove the init.gradle file afterwards.

./mvnw -U org.openrewrite.maven:rewrite-maven-plugin:run \
  -Drewrite.recipeArtifactCoordinates=io.arconia.migrations:rewrite-spring:LATEST \
  -Drewrite.activeRecipes=io.arconia.rewrite.spring.modulith2.UpgradeSpringModulith_2_1