Spring Modulith 2.2
When upgrading to Spring Modulith 2.2, refer to the Spring Modulith Release Notes for newly introduced APIs, deprecated APIs, and breaking changes. Spring Modulith 2.2 is the release line for Spring Boot 4.2, and the Spring Boot 4.2 upgrade recipe chains this recipe.
The io.arconia.rewrite.spring.modulith2.UpgradeSpringModulith_2_2 recipe automates the changes introduced in Spring Modulith 2.2. You can use it to update your project to the latest Spring Modulith 2.2.x release.
The recipe will:
-
Upgrade all
org.springframework.modulithdependencies to the 2.2.x release line. -
Replace the deprecated
IncompleteEventPublicationswithFailedEventPublications, andresubmitIncompletePublications(ResubmissionOptions)withresubmit(ResubmissionOptions). The change is made in a project only when everyIncompleteEventPublicationsusage in it has aFailedEventPublicationsequivalent, and otherwise the project is left unchanged, so it is never left half migrated. In a multi-module build, each module is checked on its own. A project that calls the overloads taking aPredicateor aDuration, or that implementsIncompleteEventPublications, is left unchanged, since those overloads resubmit every incomplete publication rather than only the failed ones and have no direct replacement.
Spring Modulith 2.2 removes the configuration properties that earlier releases had deprecated, rather than deprecating new ones. Those renames are applied by the Spring Modulith 2.0 and Spring Modulith 2.1 recipes, which the Spring Boot upgrade recipe runs before this one. If you run this recipe on its own from an earlier release, run those recipes first.
Some changes in Spring Modulith 2.2 affect behavior without requiring code changes, so the recipe does not apply them. Review them when upgrading:
-
Transactional event listeners now complete their event publication within the listener’s transaction, so the completion and the listener’s changes are committed or rolled back together. Set
spring.modulith.events.completion=in-interceptorto complete publications after the listener’s transaction instead, as earlier releases did. -
The staleness timeouts under
spring.modulith.events.stalenessmust be greater than zero, and the application fails to start otherwise. Remove a timeout set to zero to leave it unconfigured.
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_2
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_2
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_2