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.

  1. https://docs.openrewrite.org/running-recipes/popular-recipe-guides/migrate-to-java-17
  2. https://docs.openrewrite.org/running-recipes/popular-recipe-guides/migrate-to-spring-3
  3. https://docs.openrewrite.org/recipes/java/spring/framework/upgradespringframework_5_1
  4. https://docs.openrewrite.org/recipes/java/spring/boot2
  5. 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

  1. mvn rewrite:run - Run the configured recipes and apply the changes locally.
  2. 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.
  3. 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.
  4. 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.
  5. mvn rewrite:discover - Generate a report of available recipes found on the classpath.
  6. mvn rewrite:cyclonedx - Generate a CycloneDx bill of materials outlining the project’s dependencies, including transitive dependencies.