The Micronaut team has assembled a new set of OpenRewrite recipes to make upgrading from Micronaut Framework 3 to Micronaut Framework 4 quick and straightforward.
These recipes automate as much as possible from our previous “Upgrade To Micronaut Framework 4” post. The recipes will be continually updated whenever we discover new upgrade steps.
Upgrading a Maven Application to Micronaut Framework 4.
If you use Maven to build your Micronaut applications, it is easy to update from Micronaut Framework 3 to Micronaut Framework 4 with the OpenRewrite Maven plugin. You need to apply the recipes from the rewrite-micronaut module. There are two approaches:
- Modify your
pom.xmldirectly with the necessary configuration.
mvnfrom the command line, directly specifying all needed configuration via command flags.
If you’ve not used OpenRewrite before, follow the steps to modify your
pom.xml directly in an application you’d like to try to upgrade, as it will help you get more familiar with the pieces involved. Once you are comfortable with how the OpenRewrite Maven plugin works in your environment, you can apply the plugin externally via the command line (perhaps encapsulating the command in a shell script).
To enable the necessary OpenRewrite Maven goals for the upgrade, the necessary steps are:
- Enable the OpenRewrite Maven plugin
- Add the rewrite-micronaut dependency
- Activate the Micronaut 3-to-4 upgrade recipe
- Execute the newly configured Maven goals
Enabling the OpenRewrite Maven plugin
The OpenRewrite Gradle plugin
org.openrewrite.rewrite must be added to the plugins section of a Micronaut Framework 3 app
pom.xml as below:
Adding the rewrite-micronautdependency
Next, add the rewrite module
org.openrewrite.recipe:rewrite-micronaut to your dependencies section of the rewrite-maven-plugin in
Activating the Micronaut Framework 3-to-4 upgrade recipe
Finally, you must make the Micronaut Framework 4 migration recipe active by adding the following configuration to the
Complete rewrite-maven-plugin configuration
The full rewrite-maven-plugin configuration in
pom.xml should look like this:
Executing the OpenRewrite Maven goals
The OpenRewrite Maven plugin provides a set of goals for listing and executing recipes against a configured application.
To execute the configured Micronaut Framework 4 migration recipe and see what actions it will take without making any actual changes to your source code, you can execute:
If the dry run executes without any errors and you are satisfied with the changes that the OpenRewrite recipe reports, you can then apply the changes to your application source code by executing:
And that’s it, you now should have a fully functional Micronaut 4 application!
Executing the OpenRewrite Maven plugin without modifying
Once you are comfortable with how OpenRewrite works, see the alternate approach outlined in the OpenRewrite documentation of executing the OpenRewrite Maven plugin directly from the command line by passing the necessary configuration flags.
In taking this approach, you will first want to revert the OpenRewrite configuration changes (if any) that you’ve made directly to your application’s
To execute the Micronaut Framework 4 upgrade recipe, the command would be:
mvn -U org.openrewrite.maven:rewrite-maven-plugin:run -Drewrite.recipeArtifactCoordinates=org.openrewrite.recipe:rewrite-micronaut:RELEASE -Drewrite.activeRecipes=org.openrewrite.java.micronaut.Micronaut3to4Migration