Rename package name
org.openrewrite.java.ChangePackage
A recipe that will rename a package name in package statements, imports, and fully-qualified types.
Recipe source
GitHub, Issue Tracker, Maven Central
This recipe is available under the Apache License Version 2.0.
Options
Type | Name | Description | Example |
---|---|---|---|
String | oldPackageName | The package name to replace. | com.yourorg.foo |
String | newPackageName | New package name to replace the old package name with. | com.yourorg.bar |
Boolean | recursive | Optional. Recursively change subpackage names |
Used by
This recipe is used as part of the following composite recipes:
- ArchUnit 0.x upgrade
- Migrate Fest 2.x to AssertJ
- Migrate Hibernate Types to Hypersistence Utils 6.0
- Migrate Jackson from javax to jakarta namespace
- Migrate Log4j 1.x to Log4j 2.x
- Migrate Spring Cloud Sleuth 3.1 to Micrometer Tracing 1.0
- Migrate
cucumber-java8
tocucumber-java
- Migrate
javax.annotations
to SpotBugs annotations - Migrate
org.apache.ws.security
andorg.apache.ws.security.components.crypto
packages toorg.apache.wss4j.common.ext
andorg.apache.wss4j.common.crypto
packages - Migrate classes from Jackson Codehaus (legacy) to Jackson FasterXML
- Migrate deprecated
javax.activation
packages tojakarta.activation
- Migrate deprecated
javax.activation
packages tojakarta.activation
- Migrate deprecated
javax.annotation
tojakarta.annotation
- Migrate deprecated
javax.annotation
tojakarta.annotation
- Migrate deprecated
javax.batch
packages tojakarta.batch
- Migrate deprecated
javax.batch
packages tojakarta.batch
- Migrate deprecated
javax.decorator
packages tojakarta.decorator
- Migrate deprecated
javax.decorator
packages tojakarta.decorator
- Migrate deprecated
javax.ejb
packages tojakarta.ejb
- Migrate deprecated
javax.ejb
packages tojakarta.ejb
- Migrate deprecated
javax.el
packages tojakarta.el
- Migrate deprecated
javax.el
packages tojakarta.el
- Migrate deprecated
javax.enterprise
packages tojakarta.enterprise
- Migrate deprecated
javax.enterprise
packages tojakarta.enterprise
- Migrate deprecated
javax.faces
packages tojakarta.faces
- Migrate deprecated
javax.faces
packages tojakarta.faces
- Migrate deprecated
javax.inject
packages tojakarta.inject
- Migrate deprecated
javax.inject
packages tojakarta.inject
- Migrate deprecated
javax.interceptor
packages tojakarta.interceptor
- Migrate deprecated
javax.interceptor
packages tojakarta.interceptor
- Migrate deprecated
javax.jms
packages tojakarta.jms
- Migrate deprecated
javax.jms
packages tojakarta.jms
- Migrate deprecated
javax.json
packages tojakarta.json
- Migrate deprecated
javax.json
packages tojakarta.json
- Migrate deprecated
javax.jws
packages tojakarta.jws
- Migrate deprecated
javax.jws
packages tojakarta.jws
- Migrate deprecated
javax.mail
packages tojakarta.mail
- Migrate deprecated
javax.mail
packages tojakarta.mail
- Migrate deprecated
javax.persistence
packages tojakarta.persistence
- Migrate deprecated
javax.persistence
packages tojakarta.persistence
- Migrate deprecated
javax.resource
packages tojakarta.resource
- Migrate deprecated
javax.resource
packages tojakarta.resource
- Migrate deprecated
javax.security.auth.message
packages tojakarta.security.auth.message
- Migrate deprecated
javax.security.auth.message
packages tojakarta.security.auth.message
- Migrate deprecated
javax.security.enterprise
packages tojakarta.security.enterprise
- Migrate deprecated
javax.security.enterprise
packages tojakarta.security.enterprise
- Migrate deprecated
javax.security.jacc
packages tojakarta.security.jacc
- Migrate deprecated
javax.security.jacc
packages tojakarta.security.jacc
- Migrate deprecated
javax.servlet
packages tojakarta.servlet
- Migrate deprecated
javax.servlet
packages tojakarta.servlet
- Migrate deprecated
javax.soap
packages tojakarta.soap
- Migrate deprecated
javax.soap
packages tojakarta.soap
- Migrate deprecated
javax.transaction
packages tojakarta.transaction
- Migrate deprecated
javax.transaction
packages tojakarta.transaction
- Migrate deprecated
javax.validation
packages tojakarta.validation
- Migrate deprecated
javax.validation
packages tojakarta.validation
- Migrate deprecated
javax.websocket
packages tojakarta.websocket
- Migrate deprecated
javax.websocket
packages tojakarta.websocket
- Migrate deprecated
javax.ws
packages tojakarta.ws
- Migrate deprecated
javax.ws
packages tojakarta.ws
- Migrate deprecated
javax.xml.bind
packages tojakarta.xml.bind
- Migrate deprecated
javax.xml.bind
packages tojakarta.xml.bind
- Migrate deprecated
javax.xml.ws
packages tojakarta.xml.ws
- Migrate deprecated
javax.xml.ws
packages tojakarta.xml.ws
- Migrate deprecated
org.glassfish.javax.el
packages tojakarta.el
- Migrate dropWizard dependencies to Spring Boot 3.x
- Migrate from Java Faker to Datafaker
- Migrate from Micronaut 2.x to 3.x
- Migrate from OptaPlanner to Timefold Solver
- Migrate javax.mvc to 2.0 (Jakarta EE 9)
- Migrate thymeleaf dependencies to Spring Boot 3.x
- Migrate to ApacheHttpClient 5.x Classes Namespace from 4.x
- Migrate to HtmlUnit 3.x
- Migrate to Micrometer 1.13
- Migrates from Jackson 2.x to Jackson 3.x
- Migrates from Netty 4.1.x to Netty 4.2.x
- Migrates to Apache Commons Collections 4.x
- Migrates to Apache Commons Lang 3.x
- Migrates to Apache Commons Math 3.x
- Mitigate Unaffected Non-EE Jakarta 9 Packages
- Modernize a Jenkins plugin to the latest recommended versions
- Quarkus 2.x migration from Quarkus 1.x
- Rename the package name from
com.nimbusds.jose.shaded.json
tonet.minidev.json
- Replace
com.sun.net.ssl
package - Update Apache Commons Email to Email2 for Jakarta
- Update the Micronaut Data library
- Update to Micronaut Email 2.x
- Update to Micronaut Validation 4.x
- Upgrade to Axonframework 4.x Jakarta
- Upgrade to Axonframework 4.x Javax
- Upgrade to Cucumber-JVM 5.x
- Use Arquillian JUnit 5 Extension
- Use OkHttp 3 MockWebServer for JUnit 5
- Use
com.sun.xml.bind.*
instead ofcom.sun.xml.internal.bind.*
- Use
java.security.cert
instead ofjavax.security.cert
- Use
java.security.cert
instead ofjavax.security.cert
- Use
javax.net.ssl
instead ofcom.sun.net.ssl
- io.quarkus.updates.core.quarkus37.HibernateSearchOutboxPolling
Usage
This recipe has required configuration parameters. Recipes with required configuration parameters cannot be activated directly (unless you are running them via the Moderne CLI). To activate this recipe you must create a new recipe which fills in the required parameters. In your rewrite.yml
create a new recipe with a unique name. For example: com.yourorg.ChangePackageExample
.
Here's how you can define and customize such a recipe within your rewrite.yml:
---
type: specs.openrewrite.org/v1beta/recipe
name: com.yourorg.ChangePackageExample
displayName: Rename package name example
recipeList:
- org.openrewrite.java.ChangePackage:
oldPackageName: com.yourorg.foo
newPackageName: com.yourorg.bar
Now that com.yourorg.ChangePackageExample
has been defined, activate it in your build file:
- Gradle
- Maven
- Moderne CLI
- Add the following to your
build.gradle
file:
plugins {
id("org.openrewrite.rewrite") version("latest.release")
}
rewrite {
activeRecipe("com.yourorg.ChangePackageExample")
setExportDatatables(true)
}
repositories {
mavenCentral()
}
- Run
gradle rewriteRun
to run the recipe.
- Add the following to your
pom.xml
file:
<project>
<build>
<plugins>
<plugin>
<groupId>org.openrewrite.maven</groupId>
<artifactId>rewrite-maven-plugin</artifactId>
<version>6.15.0</version>
<configuration>
<exportDatatables>true</exportDatatables>
<activeRecipes>
<recipe>com.yourorg.ChangePackageExample</recipe>
</activeRecipes>
</configuration>
</plugin>
</plugins>
</build>
</project>
- Run
mvn rewrite:run
to run the recipe.
You will need to have configured the Moderne CLI on your machine before you can run the following command.
mod run . --recipe ChangePackage --recipe-option "oldPackageName=com.yourorg.foo" --recipe-option "newPackageName=com.yourorg.bar"
If the recipe is not available locally, then you can install it using:
mod config recipes jar install org.openrewrite:rewrite-java:8.59.1
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
- SourcesFileResults
- SourcesFileErrors
- RecipeRunStats
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 (ns) | The total time spent across the scanning phase of this recipe. |
99th percentile scanning time (ns) | 99 out of 100 scans completed in this amount of time. |
Max scanning time (ns) | The max time scanning any one source file. |
Cumulative edit time (ns) | The total time spent across the editing phase of this recipe. |
99th percentile edit time (ns) | 99 out of 100 edits completed in this amount of time. |
Max edit time (ns) | The max time editing any one source file. |
Contributors
Tracey Yoshima, Laurens Westerlaken, Jonathan Schnéider, Sam Snyder, Tim te Beek, Knut Wannheden, Nick McKinney, Patrick, Patrik Ivarsson, Patrick Way, Roberto Cortez, Dinar Shagaliev