This repository showcases the integration of OpenRewrite with Maven for code migration purposes.
The migration recipe is defined to transition from azure-core to azure-core-v2 libraries.
The migration recipe is defined in the java-rewrite-core module as detailed below:
### Recipe Configuration for OpenRewrite
type: specs.openrewrite.org/v1beta/recipe
name: com.azure.rewrite.java.core.MigrateAzureCoreSamplesToAzureCoreV2
displayName: Migrate azure-core samples to azure-core-v2
description: This recipe migrates the samples in azure-core to azure-core-v2
recipeList:
- org.openrewrite.java.ChangePackage:
oldPackageName: com.azure
newPackageName: io.clientcore
recursive: trueYou can find the recipe configuration in the rewrite.yml file here.
The OpenRewrite Maven plugin is configured in the java-rewrite-core module to run the migration recipe on the sample project
as follows:
<plugin>
<groupId>org.openrewrite.maven</groupId>
<artifactId>rewrite-maven-plugin</artifactId>
<version>5.7.1</version>
<configuration>
<activeRecipes>
<recipe>com.azure.rewrite.java.core.MigrateAzureCoreSamplesToAzureCoreV2</recipe>
</activeRecipes>
</configuration>
<dependencies>
<dependency>
<groupId>com.azure</groupId>
<artifactId>rewrite-java-core</artifactId>
<version>1.0.0</version>
</dependency>
</dependencies>
</plugin>The plugin configuration is defined in the pom.xml file here.
The rewrite-sample module is configured to use the openrewrite-maven-plugin to run the OpenRewrite recipe on the sample project.
The rewrite-sample module contains the modules azure-ai-translation-text-v1 and azure-ai-translation-text-v2
to demonstrate the migration of code from azure-core to azure-core-v2.
To run the OpenRewrite recipe in dry-run mode, execute the following command:
mvn rewrite:dryRunThis will generate a file rewrite.patch in target/rewrite directory.
To actually apply the changes to the sample project, execute the following command:
mvn rewrite:runRefer to Recipe Testing for information on testing the recipe with unit tests.
- Rewrite Recipe Starter: Template for building your own recipe JARs
- Best practices for writing recipes
- Collaboration Proposal: collaboration with OpenRewrite