Maven - using openrewrite for version upgrades
openrewrite makes it a little easier to change versions of jdk and spring dependencies used in applications. It is not a silver bullet. But it helps speed things up.
- https://docs.openrewrite.org/running-recipes/popular-recipe-guides/migrate-to-java-17
- https://docs.openrewrite.org/running-recipes/popular-recipe-guides/migrate-to-spring-3
- https://docs.openrewrite.org/recipes/java/spring/framework/upgradespringframework_5_1
- https://docs.openrewrite.org/recipes/java/spring/boot2
- https://docs.openrewrite.org/recipes/java/spring/boot3
e.g. example using multiple reciples in the same plugin configuration
<build>
<plugins>
<plugin>
<groupId>org.openrewrite.maven</groupId>
<artifactId>rewrite-maven-plugin</artifactId>
<version>5.28.0</version>
<configuration>
<activeRecipes>
<recipe>org.openrewrite.java.migrate.UpgradeToJava17</recipe>
<recipe>org.openrewrite.java.spring.boot3.UpgradeSpringBoot_3_2</recipe>
<!-- <recipe>org.openrewrite.java.spring.boot2.UpgradeSpringBoot_2_7</recipe> for upgrading from lower versions of springboot to version 2.7 -->
<recipe>org.openrewrite.java.spring.framework.UpgradeSpringFramework_5_1</recipe>
</activeRecipes>
</configuration>
<dependencies>
<dependency>
<groupId>org.openrewrite.recipe</groupId>
<artifactId>rewrite-migrate-java</artifactId>
<version>2.12.0</version>
</dependency>
<dependency>
<groupId>org.openrewrite.recipe</groupId>
<artifactId>rewrite-spring</artifactId>
<version>5.8.0</version>
</dependency>
</dependencies>
</plugin>
</plugins>
</build>
Run this with the command:
mvn org.openrewrite.maven:rewrite-maven-plugin:run
The rewrite
plugin has many other goals: https://docs.openrewrite.org/reference/rewrite-maven-plugin
- mvn rewrite:run - Run the configured recipes and apply the changes locally.
- mvn rewrite:runNoFork - Run the configured recipes and apply the changes locally. This variant does not fork the Maven life cycle and can be a more efficient choice when using Rewrite within a CI workflow when combined with other Maven goals.
- mvn rewrite:dryRun - Generate warnings to the console for any recipe that would make changes and generates a diff file in each maven modules’ target folder.
- mvn rewrite:dryRunNoFork - Generate warnings to the console for any recipe that would make changes and generates a diff file in each maven modules’ target folder. This variant does not fork the Maven life cycle and can be a more efficient choice when using Rewrite within a CI workflow when combined with other Maven goals.
- mvn rewrite:discover - Generate a report of available recipes found on the classpath.
- mvn rewrite:cyclonedx - Generate a CycloneDx bill of materials outlining the project’s dependencies, including transitive dependencies.