Migrate from Micronaut 2.x to 3.x
org.openrewrite.java.micronaut.Micronaut2to3Migration
This recipe will apply changes required for migrating from Micronaut 2 to Micronaut 3.
Recipe source
GitHub, Issue Tracker, Maven Central
This recipe is composed of more than one recipe. If you want to customize the set of recipes this is composed of, you can find and copy the GitHub source for the recipe from the link above.
License
This recipe is available under the Apache License 2.0.
Definition
- Recipe List
- Yaml Recipe List
- De-capitalize
BeanIntrospection
getProperty(..)
andgetRequiredProperty(..)
name arguments - Copy non-inherited annotations from super class
- Change factory method return types to reflect their resolved return type
- Convert
OncePerRequestServerFilter
extensions toHttpServerFilter
Provider
implementation beans to Micronaut@Factory
- Add
@Introspected
to classes requiring a map representation - Fix deprecated no-arg
ExceptionHandler
constructors - Upgrade Maven parent project version
- groupId:
io.micronaut
- artifactId:
micronaut-parent
- newVersion:
3.x
- groupId:
- Upgrade Maven dependency version
- groupId:
io.micronaut
- artifactId:
micronaut-bom
- newVersion:
3.x
- overrideManagedVersion:
true
- groupId:
- Upgrade gradle.properties Micronaut version
- newVersion:
3.x
- newVersion:
- Upgrade
micronaut.version
Maven property- newVersion:
3.x
- newVersion:
- Rename package name
- oldPackageName:
io.micronaut.configuration.cassandra
- newPackageName:
io.micronaut.cassandra
- oldPackageName:
- Rename package name
- oldPackageName:
io.micronaut.configuration.security.ldap
- newPackageName:
io.micronaut.security.ldap
- oldPackageName:
- Change method name
- methodPattern:
io.micronaut.context.ApplicationContext build(..)
- newMethodName:
builder
- methodPattern:
- Change type
- oldFullyQualifiedTypeName:
io.micronaut.core.async.SupplierUtil
- newFullyQualifiedTypeName:
io.micronaut.core.util.SupplierUtil
- oldFullyQualifiedTypeName:
- Change method name
- methodPattern:
io.micronaut.http.netty.stream.DelegateHttpRequest getMethod()
- newMethodName:
method
- methodPattern:
- Change method name
- methodPattern:
io.micronaut.http.netty.stream.DelegateHttpResponse getStatus()
- newMethodName:
status
- methodPattern:
- Change method name
- methodPattern:
io.micronaut.http.server.netty.DelegateHttpResponse getStatus()
- newMethodName:
status
- methodPattern:
- Change method name
- methodPattern:
io.micronaut.http.netty.stream.DelegateHttpRequest getUri()
- newMethodName:
uri
- methodPattern:
- Change method name
- methodPattern:
io.micronaut.http.netty.stream.DelegateHttpMessage getDecoderResult()
- newMethodName:
decoderResult
- methodPattern:
- Change method name
- methodPattern:
io.micronaut.http.netty.stream.DelegateHttpMessage getProtocolVersion()
- newMethodName:
protocolVersion
- methodPattern:
- Change type
- oldFullyQualifiedTypeName:
io.micronaut.management.endpoint.beans.impl.RxJavaBeanDefinitionDataCollector
- newFullyQualifiedTypeName:
io.micronaut.management.endpoint.beans.impl.DefaultBeanDefinitionDataCollector
- oldFullyQualifiedTypeName:
- Change type
- oldFullyQualifiedTypeName:
io.micronaut.management.endpoint.routes.impl.RxJavaRouteDataCollector
- newFullyQualifiedTypeName:
io.micronaut.management.endpoint.routes.impl.DefaultRouteDataCollector
- oldFullyQualifiedTypeName:
- Change type
- oldFullyQualifiedTypeName:
io.micronaut.management.health.aggregator.RxJavaHealthAggregator
- newFullyQualifiedTypeName:
io.micronaut.management.health.aggregator.DefaultHealthAggregator
- oldFullyQualifiedTypeName:
- Change type
- oldFullyQualifiedTypeName:
io.micronaut.messaging.annotation.Body
- newFullyQualifiedTypeName:
io.micronaut.messaging.annotation.MessageBody
- oldFullyQualifiedTypeName:
- Change type
- oldFullyQualifiedTypeName:
io.micronaut.messaging.annotation.Headers
- newFullyQualifiedTypeName:
io.micronaut.messaging.annotation.MessageHeaders
- oldFullyQualifiedTypeName:
- Change method name
- methodPattern:
io.micronaut.rss.itunespodcast.ItunesPodcast isExplict()
- newMethodName:
isExplicit
- methodPattern:
- Change method name
- methodPattern:
io.micronaut.rss.itunespodcast.ItunesPodcast setExplict(boolean)
- newMethodName:
setExplicit
- methodPattern:
- Change method name
- methodPattern:
io.micronaut.rss.itunespodcast.ItunesPodcast explict(boolean)
- newMethodName:
setExplicit
- methodPattern:
- Change method name
- methodPattern:
io.micronaut.rss.itunespodcast.ItunesPodcastEpisode isExplict()
- newMethodName:
isExplicit
- methodPattern:
- Change type
- oldFullyQualifiedTypeName:
io.micronaut.runtime.server.EmbeddedServerInstance
- newFullyQualifiedTypeName:
io.micronaut.discovery.EmbeddedServerInstance
- oldFullyQualifiedTypeName:
- Change type
- oldFullyQualifiedTypeName:
io.micronaut.http.client.RxHttpClient
- newFullyQualifiedTypeName:
io.micronaut.rxjava2.http.client.RxHttpClient
- oldFullyQualifiedTypeName:
- Change type
- oldFullyQualifiedTypeName:
io.micronaut.http.client.RxProxyHttpClient
- newFullyQualifiedTypeName:
io.micronaut.rxjava2.http.client.proxy.RxProxyHttpClient
- oldFullyQualifiedTypeName:
- Change type
- oldFullyQualifiedTypeName:
io.micronaut.http.client.RxStreamingHttpClient
- newFullyQualifiedTypeName:
io.micronaut.rxjava2.http.client.RxStreamingHttpClient
- oldFullyQualifiedTypeName:
- Change type
- oldFullyQualifiedTypeName:
io.micronaut.http.client.sse.RxSseClient
- newFullyQualifiedTypeName:
io.micronaut.rxjava2.http.client.sse.RxSseClient
- oldFullyQualifiedTypeName:
- Change type
- oldFullyQualifiedTypeName:
io.micronaut.websocket.RxWebSocketClient
- newFullyQualifiedTypeName:
io.micronaut.rxjava2.http.client.websockets.RxWebSocketClient
- oldFullyQualifiedTypeName:
- Change method name
- methodPattern:
io.micronaut.web.router accept(io.micronaut.http.MediaType)
- newMethodName:
doesConsume
- methodPattern:
- Change method name
- methodPattern:
io.micronaut.web.router.Route acceptAll()
- newMethodName:
consumesAll
- methodPattern:
- Change method name
- methodPattern:
io.micronaut.web.router.RouteMatch accept(io.micronaut.http.MediaType)
- newMethodName:
doesConsume
- methodPattern:
- Change method name
- methodPattern:
io.micronaut.web.router.RouteMatch explicitAccept(io.micronaut.http.MediaType)
- newMethodName:
explicitlyConsumes
- methodPattern:
- Change type
- oldFullyQualifiedTypeName:
javax.annotation.Nullable
- newFullyQualifiedTypeName:
io.micronaut.core.annotation.Nullable
- oldFullyQualifiedTypeName:
- Change type
- oldFullyQualifiedTypeName:
javax.annotation.Nonnull
- newFullyQualifiedTypeName:
io.micronaut.core.annotation.NonNull
- oldFullyQualifiedTypeName:
- Change type
- oldFullyQualifiedTypeName:
io.micronaut.test.annotation.MicronautTest
- newFullyQualifiedTypeName:
io.micronaut.test.extensions.junit5.annotation.MicronautTest
- oldFullyQualifiedTypeName:
---
type: specs.openrewrite.org/v1beta/recipe
name: org.openrewrite.java.micronaut.Micronaut2to3Migration
displayName: Migrate from Micronaut 2.x to 3.x
description: This recipe will apply changes required for migrating from Micronaut 2 to Micronaut 3.
recipeList:
- org.openrewrite.java.micronaut.BeanPropertyCapitalizationStrategy
- org.openrewrite.java.micronaut.CopyNonInheritedAnnotations
- org.openrewrite.java.micronaut.SubclassesReturnedFromFactoriesNotInjectable
- org.openrewrite.java.micronaut.OncePerRequestHttpServerFilterToHttpServerFilter
- org.openrewrite.java.micronaut.ProviderImplementationsToMicronautFactories
- org.openrewrite.java.micronaut.TypeRequiresIntrospection
- org.openrewrite.java.micronaut.FixDeprecatedExceptionHandlerConstructors
- org.openrewrite.maven.UpgradeParentVersion:
groupId: io.micronaut
artifactId: micronaut-parent
newVersion: 3.x
- org.openrewrite.maven.UpgradeDependencyVersion:
groupId: io.micronaut
artifactId: micronaut-bom
newVersion: 3.x
overrideManagedVersion: true
- org.openrewrite.java.micronaut.UpgradeMicronautGradlePropertiesVersion:
newVersion: 3.x
- org.openrewrite.java.micronaut.UpgradeMicronautMavenPropertyVersion:
newVersion: 3.x
- org.openrewrite.java.ChangePackage:
oldPackageName: io.micronaut.configuration.cassandra
newPackageName: io.micronaut.cassandra
- org.openrewrite.java.ChangePackage:
oldPackageName: io.micronaut.configuration.security.ldap
newPackageName: io.micronaut.security.ldap
- org.openrewrite.java.ChangeMethodName:
methodPattern: io.micronaut.context.ApplicationContext build(..)
newMethodName: builder
- org.openrewrite.java.ChangeType:
oldFullyQualifiedTypeName: io.micronaut.core.async.SupplierUtil
newFullyQualifiedTypeName: io.micronaut.core.util.SupplierUtil
- org.openrewrite.java.ChangeMethodName:
methodPattern: io.micronaut.http.netty.stream.DelegateHttpRequest getMethod()
newMethodName: method
- org.openrewrite.java.ChangeMethodName:
methodPattern: io.micronaut.http.netty.stream.DelegateHttpResponse getStatus()
newMethodName: status
- org.openrewrite.java.ChangeMethodName:
methodPattern: io.micronaut.http.server.netty.DelegateHttpResponse getStatus()
newMethodName: status
- org.openrewrite.java.ChangeMethodName:
methodPattern: io.micronaut.http.netty.stream.DelegateHttpRequest getUri()
newMethodName: uri
- org.openrewrite.java.ChangeMethodName:
methodPattern: io.micronaut.http.netty.stream.DelegateHttpMessage getDecoderResult()
newMethodName: decoderResult
- org.openrewrite.java.ChangeMethodName:
methodPattern: io.micronaut.http.netty.stream.DelegateHttpMessage getProtocolVersion()
newMethodName: protocolVersion
- org.openrewrite.java.ChangeType:
oldFullyQualifiedTypeName: io.micronaut.management.endpoint.beans.impl.RxJavaBeanDefinitionDataCollector
newFullyQualifiedTypeName: io.micronaut.management.endpoint.beans.impl.DefaultBeanDefinitionDataCollector
- org.openrewrite.java.ChangeType:
oldFullyQualifiedTypeName: io.micronaut.management.endpoint.routes.impl.RxJavaRouteDataCollector
newFullyQualifiedTypeName: io.micronaut.management.endpoint.routes.impl.DefaultRouteDataCollector
- org.openrewrite.java.ChangeType:
oldFullyQualifiedTypeName: io.micronaut.management.health.aggregator.RxJavaHealthAggregator
newFullyQualifiedTypeName: io.micronaut.management.health.aggregator.DefaultHealthAggregator
- org.openrewrite.java.ChangeType:
oldFullyQualifiedTypeName: io.micronaut.messaging.annotation.Body
newFullyQualifiedTypeName: io.micronaut.messaging.annotation.MessageBody
- org.openrewrite.java.ChangeType:
oldFullyQualifiedTypeName: io.micronaut.messaging.annotation.Headers
newFullyQualifiedTypeName: io.micronaut.messaging.annotation.MessageHeaders
- org.openrewrite.java.ChangeMethodName:
methodPattern: io.micronaut.rss.itunespodcast.ItunesPodcast isExplict()
newMethodName: isExplicit
- org.openrewrite.java.ChangeMethodName:
methodPattern: io.micronaut.rss.itunespodcast.ItunesPodcast setExplict(boolean)
newMethodName: setExplicit
- org.openrewrite.java.ChangeMethodName:
methodPattern: io.micronaut.rss.itunespodcast.ItunesPodcast explict(boolean)
newMethodName: setExplicit
- org.openrewrite.java.ChangeMethodName:
methodPattern: io.micronaut.rss.itunespodcast.ItunesPodcastEpisode isExplict()
newMethodName: isExplicit
- org.openrewrite.java.ChangeType:
oldFullyQualifiedTypeName: io.micronaut.runtime.server.EmbeddedServerInstance
newFullyQualifiedTypeName: io.micronaut.discovery.EmbeddedServerInstance
- org.openrewrite.java.ChangeType:
oldFullyQualifiedTypeName: io.micronaut.http.client.RxHttpClient
newFullyQualifiedTypeName: io.micronaut.rxjava2.http.client.RxHttpClient
- org.openrewrite.java.ChangeType:
oldFullyQualifiedTypeName: io.micronaut.http.client.RxProxyHttpClient
newFullyQualifiedTypeName: io.micronaut.rxjava2.http.client.proxy.RxProxyHttpClient
- org.openrewrite.java.ChangeType:
oldFullyQualifiedTypeName: io.micronaut.http.client.RxStreamingHttpClient
newFullyQualifiedTypeName: io.micronaut.rxjava2.http.client.RxStreamingHttpClient
- org.openrewrite.java.ChangeType:
oldFullyQualifiedTypeName: io.micronaut.http.client.sse.RxSseClient
newFullyQualifiedTypeName: io.micronaut.rxjava2.http.client.sse.RxSseClient
- org.openrewrite.java.ChangeType:
oldFullyQualifiedTypeName: io.micronaut.websocket.RxWebSocketClient
newFullyQualifiedTypeName: io.micronaut.rxjava2.http.client.websockets.RxWebSocketClient
- org.openrewrite.java.ChangeMethodName:
methodPattern: io.micronaut.web.router accept(io.micronaut.http.MediaType)
newMethodName: doesConsume
- org.openrewrite.java.ChangeMethodName:
methodPattern: io.micronaut.web.router.Route acceptAll()
newMethodName: consumesAll
- org.openrewrite.java.ChangeMethodName:
methodPattern: io.micronaut.web.router.RouteMatch accept(io.micronaut.http.MediaType)
newMethodName: doesConsume
- org.openrewrite.java.ChangeMethodName:
methodPattern: io.micronaut.web.router.RouteMatch explicitAccept(io.micronaut.http.MediaType)
newMethodName: explicitlyConsumes
- org.openrewrite.java.ChangeType:
oldFullyQualifiedTypeName: javax.annotation.Nullable
newFullyQualifiedTypeName: io.micronaut.core.annotation.Nullable
- org.openrewrite.java.ChangeType:
oldFullyQualifiedTypeName: javax.annotation.Nonnull
newFullyQualifiedTypeName: io.micronaut.core.annotation.NonNull
- org.openrewrite.java.ChangeType:
oldFullyQualifiedTypeName: io.micronaut.test.annotation.MicronautTest
newFullyQualifiedTypeName: io.micronaut.test.extensions.junit5.annotation.MicronautTest
Usage
This recipe has no required configuration options. It can be activated by adding a dependency on org.openrewrite.recipe:rewrite-micronaut
in your build file or by running a shell command (in which case no build changes are needed):
- Gradle
- Gradle init script
- Maven POM
- Maven Command Line
- Moderne CLI
- Add the following to your
build.gradle
file:
plugins {
id("org.openrewrite.rewrite") version("6.29.0")
}
rewrite {
activeRecipe("org.openrewrite.java.micronaut.Micronaut2to3Migration")
setExportDatatables(true)
}
repositories {
mavenCentral()
}
dependencies {
rewrite("org.openrewrite.recipe:rewrite-micronaut:2.14.0")
}
- Run
gradle rewriteRun
to run the recipe.
- Create a file named
init.gradle
in the root of your project.
initscript {
repositories {
maven { url "https://plugins.gradle.org/m2" }
}
dependencies { classpath("org.openrewrite:plugin:6.29.0") }
}
rootProject {
plugins.apply(org.openrewrite.gradle.RewritePlugin)
dependencies {
rewrite("org.openrewrite.recipe:rewrite-micronaut:2.14.0")
}
rewrite {
activeRecipe("org.openrewrite.java.micronaut.Micronaut2to3Migration")
setExportDatatables(true)
}
afterEvaluate {
if (repositories.isEmpty()) {
repositories {
mavenCentral()
}
}
}
}
- Run the recipe.
gradle --init-script init.gradle rewriteRun
- Add the following to your
pom.xml
file:
<project>
<build>
<plugins>
<plugin>
<groupId>org.openrewrite.maven</groupId>
<artifactId>rewrite-maven-plugin</artifactId>
<version>5.47.0</version>
<configuration>
<exportDatatables>true</exportDatatables>
<activeRecipes>
<recipe>org.openrewrite.java.micronaut.Micronaut2to3Migration</recipe>
</activeRecipes>
</configuration>
<dependencies>
<dependency>
<groupId>org.openrewrite.recipe</groupId>
<artifactId>rewrite-micronaut</artifactId>
<version>2.14.0</version>
</dependency>
</dependencies>
</plugin>
</plugins>
</build>
</project>
- Run
mvn rewrite:run
to run the recipe.
You will need to have Maven installed on your machine before you can run the following command.
mvn -U org.openrewrite.maven:rewrite-maven-plugin:run -Drewrite.recipeArtifactCoordinates=org.openrewrite.recipe:rewrite-micronaut:RELEASE -Drewrite.activeRecipes=org.openrewrite.java.micronaut.Micronaut2to3Migration -Drewrite.exportDatatables=true
You will need to have configured the Moderne CLI on your machine before you can run the following command.
mod run . --recipe Micronaut2to3Migration
If the recipe is not available locally, then you can install it using:
mod config recipes jar install org.openrewrite.recipe:rewrite-micronaut:2.14.0
See how this recipe works across multiple open-source repositories
Run this recipe on OSS repos at scale with the Moderne SaaS.
The community edition of the Moderne platform enables you to easily run recipes across thousands of open-source repositories.
Please contact Moderne for more information about safely running the recipes on your own codebase in a private SaaS.
Data Tables
Source files that had results
org.openrewrite.table.SourcesFileResults
Source files that were modified by the recipe run.
Column Name | Description |
---|---|
Source path before the run | The source path of the file before the run. null when a source file was created during the run. |
Source path after the run | A recipe may modify the source path. This is the path after the run. null when a source file was deleted during the run. |
Parent of the recipe that made changes | In a hierarchical recipe, the parent of the recipe that made a change. Empty if this is the root of a hierarchy or if the recipe is not hierarchical at all. |
Recipe that made changes | The specific recipe that made a change. |
Estimated time saving | An estimated effort that a developer to fix manually instead of using this recipe, in unit of seconds. |
Cycle | The recipe cycle in which the change was made. |
Source files that errored on a recipe
org.openrewrite.table.SourcesFileErrors
The details of all errors produced by a recipe run.
Column Name | Description |
---|---|
Source path | The file that failed to parse. |
Recipe that made changes | The specific recipe that made a change. |
Stack trace | The stack trace of the failure. |
Recipe performance
org.openrewrite.table.RecipeRunStats
Statistics used in analyzing the performance of recipes.
Column Name | Description |
---|---|
The recipe | The recipe whose stats are being measured both individually and cumulatively. |
Source file count | The number of source files the recipe ran over. |
Source file changed count | The number of source files which were changed in the recipe run. Includes files created, deleted, and edited. |
Cumulative scanning time | The total time spent across the scanning phase of this recipe. |
99th percentile scanning time | 99 out of 100 scans completed in this amount of time. |
Max scanning time | The max time scanning any one source file. |
Cumulative edit time | The total time spent across the editing phase of this recipe. |
99th percentile edit time | 99 out of 100 edits completed in this amount of time. |
Max edit time | The max time editing any one source file. |
Contributors
Patrick, Knut Wannheden, Patrick Way, Tim te Beek, Sam Snyder, Tyler Van Gorder, Jeremy Grelle, Jonathan Schneider, Tracey Yoshima, Jonathan Schnéider, Aaron Gershman, Aaron Gershman