Migrate to JDK 21 and Springboot 3.3 using Maven and openrewrite.

Hemant
3 min readJul 31, 2024

--

Latest version of Java and Springboot have lot to offer but how can we easily migrate old version of these applications to newer versions of java and springboot?

Recently I got a chance to upgrade a lot of microservices to Java 21and springboot 3.3 and there I got to know about openrewrite. Openrewrite provides plugin and recipies as per the task.

In this article I will explain steps to upgrade an application to java 21 and spring 3.3. Existing version are java 1.8 and springboot 2.2

I am performing below steps in MacOS but these same steps should work on windows and linux also.

Steps in this article :

Step 1: Setup existing application

Step 2: Run openrewrite recipe to Upgrade Java to 21

Step 3: Upgrade sprinboot versions

Step 4. Cleaup

Step 1: Setup existing application

I am using seed starter manager application. this is an old application based on Java 8, Springboot 2.2 and thymeleaf.

Clone repository from github using below command

git clone https://github.com/spring-lab-01/references.git && cd references/seed-starter-manager

Step 2: Run openrewrite recipe to Upgrade Java to 21

Add lombok version to 1.18.34 for compatibility with java 21.

Run below command in Terminal.

mvn -U org.openrewrite.maven:rewrite-maven-plugin:run -Drewrite.recipeArtifactCoordinates=org.openrewrite.recipe:rewrite-migrate-java:RELEASE -Drewrite.activeRecipes=org.openrewrite.java.migrate.UpgradeToJava21 -Drewrite.exportDatatables=true

Wait for it to success.

Now java version is updated and can be verified under pom.xml

Step 3: Upgrade sprinboot versions

Springboot versions will be updated in sequence. First 3.0 then 3.1, 3,2 and finally 3.3

Upgrade to springboot 3.0

Add openrewrite 3.0 plugin to pom.xml

     <plugin>
<groupId>org.openrewrite.maven</groupId>
<artifactId>rewrite-maven-plugin</artifactId>
<version>5.36.0</version>
<configuration>
<exportDatatables>true</exportDatatables>
<activeRecipes>
<recipe>org.openrewrite.java.spring.boot3.UpgradeSpringBoot_3_0</recipe>
</activeRecipes>
</configuration>
<dependencies>
<dependency>
<groupId>org.openrewrite.recipe</groupId>
<artifactId>rewrite-spring</artifactId>
<version>5.15.0</version>
</dependency>
</dependencies>
</plugin>

Run this plugin using command

mvn rewrite:run

it should end with success like in above image.

Now Verify in pom.xml , spring-boot-starter-parent version should be <version>3.0.13</version>

Upgrade to springboot 3.1

Now change rewrite-maven-plugin recipe in pom.xml for 3.1 as per below image

Run mvn rewrite command again in terminal.

mvn rewrite:run

Upgrade to springboot 3.2

Now change plugin recipe for 3.2 as per below image and run mvn rewrite command.

Upgrade to springboot 3.3

Now change plugin recipe for 3.3 as per below image and run mvn rewrite command.

Now Springboot version is upgraded to 3.3 and can be verified in pom.xml.

Check if all success using below command.

mvn clean package

Step 4. Cleaup

Finally remove rewrite-maven-plugin from pom.xml, we don’t need this anymore.

Conclusion

In this article we explored quick steps to upgrade java and springboot based applications to latest versions using maven and rewrite.

References -

https://github.com/openrewrite

https://docs.openrewrite.org/recipes/java/migrate/upgradetojava21

https://github.com/spring-lab-01/references

--

--

Hemant

Lead Software Engineer @JPMorgan & Chase. Writes about Java, AWS and System Design