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 WordUtilsto Apache Commons Text
- Migrate cucumber-java8tocucumber-java
- Migrate javax.annotationsto SpotBugs annotations
- Migrate org.apache.ws.securityandorg.apache.ws.security.components.cryptopackages toorg.apache.wss4j.common.extandorg.apache.wss4j.common.cryptopackages
- Migrate classes from Jackson Codehaus (legacy) to Jackson FasterXML
- Migrate deprecated javax.activationpackages tojakarta.activation
- Migrate deprecated javax.activationpackages tojakarta.activation
- Migrate deprecated javax.annotationtojakarta.annotation
- Migrate deprecated javax.annotationtojakarta.annotation
- Migrate deprecated javax.batchpackages tojakarta.batch
- Migrate deprecated javax.batchpackages tojakarta.batch
- Migrate deprecated javax.decoratorpackages tojakarta.decorator
- Migrate deprecated javax.decoratorpackages tojakarta.decorator
- Migrate deprecated javax.ejbpackages tojakarta.ejb
- Migrate deprecated javax.ejbpackages tojakarta.ejb
- Migrate deprecated javax.elpackages tojakarta.el
- Migrate deprecated javax.elpackages tojakarta.el
- Migrate deprecated javax.enterprisepackages tojakarta.enterprise
- Migrate deprecated javax.enterprisepackages tojakarta.enterprise
- Migrate deprecated javax.facespackages tojakarta.faces
- Migrate deprecated javax.facespackages tojakarta.faces
- Migrate deprecated javax.injectpackages tojakarta.inject
- Migrate deprecated javax.injectpackages tojakarta.inject
- Migrate deprecated javax.interceptorpackages tojakarta.interceptor
- Migrate deprecated javax.interceptorpackages tojakarta.interceptor
- Migrate deprecated javax.jmspackages tojakarta.jms
- Migrate deprecated javax.jmspackages tojakarta.jms
- Migrate deprecated javax.jsonpackages tojakarta.json
- Migrate deprecated javax.jsonpackages tojakarta.json
- Migrate deprecated javax.jsppackages tojakarta.jsp
- Migrate deprecated javax.jwspackages tojakarta.jws
- Migrate deprecated javax.jwspackages tojakarta.jws
- Migrate deprecated javax.mailpackages tojakarta.mail
- Migrate deprecated javax.mailpackages tojakarta.mail
- Migrate deprecated javax.persistencepackages tojakarta.persistence
- Migrate deprecated javax.persistencepackages tojakarta.persistence
- Migrate deprecated javax.resourcepackages tojakarta.resource
- Migrate deprecated javax.resourcepackages tojakarta.resource
- Migrate deprecated javax.security.auth.messagepackages tojakarta.security.auth.message
- Migrate deprecated javax.security.auth.messagepackages tojakarta.security.auth.message
- Migrate deprecated javax.security.enterprisepackages tojakarta.security.enterprise
- Migrate deprecated javax.security.enterprisepackages tojakarta.security.enterprise
- Migrate deprecated javax.security.jaccpackages tojakarta.security.jacc
- Migrate deprecated javax.security.jaccpackages tojakarta.security.jacc
- Migrate deprecated javax.servletpackages tojakarta.servlet
- Migrate deprecated javax.servletpackages tojakarta.servlet
- Migrate deprecated javax.soappackages tojakarta.soap
- Migrate deprecated javax.soappackages tojakarta.soap
- Migrate deprecated javax.transactionpackages tojakarta.transaction
- Migrate deprecated javax.transactionpackages tojakarta.transaction
- Migrate deprecated javax.validationpackages tojakarta.validation
- Migrate deprecated javax.validationpackages tojakarta.validation
- Migrate deprecated javax.websocketpackages tojakarta.websocket
- Migrate deprecated javax.websocketpackages tojakarta.websocket
- Migrate deprecated javax.wspackages tojakarta.ws
- Migrate deprecated javax.wspackages tojakarta.ws
- Migrate deprecated javax.xml.bindpackages tojakarta.xml.bind
- Migrate deprecated javax.xml.bindpackages tojakarta.xml.bind
- Migrate deprecated javax.xml.wspackages tojakarta.xml.ws
- Migrate deprecated javax.xml.wspackages tojakarta.xml.ws
- Migrate deprecated org.apache.commons.fileloadpackages toorg.apache.commons.fileload.core
- Migrate deprecated org.glassfish.javax.elpackages 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 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.jsontonet.minidev.json
- Replace com.sun.net.sslpackage
- Update Apache Commons Email to Email2 for Jakarta
- Update Apache Commons FileUpload2 package for EE10
- Update Jackson package names from 2.x to 3.x
- 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.certinstead ofjavax.security.cert
- Use java.security.certinstead ofjavax.security.cert
- Use javax.net.sslinstead 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.gradlefile:
plugins {
    id("org.openrewrite.rewrite") version("latest.release")
}
rewrite {
    activeRecipe("com.yourorg.ChangePackageExample")
    setExportDatatables(true)
}
repositories {
    mavenCentral()
}
- Run gradle rewriteRunto run the recipe.
- Add the following to your pom.xmlfile:
<project>
  <build>
    <plugins>
      <plugin>
        <groupId>org.openrewrite.maven</groupId>
        <artifactId>rewrite-maven-plugin</artifactId>
        <version>6.22.1</version>
        <configuration>
          <exportDatatables>true</exportDatatables>
          <activeRecipes>
            <recipe>com.yourorg.ChangePackageExample</recipe>
          </activeRecipes>
        </configuration>
      </plugin>
    </plugins>
  </build>
</project>
- Run mvn rewrite:runto 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.64.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
- 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. nullwhen 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. nullwhen 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. | 
| 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. | 
| Max edit time (ns) | The max time editing any one source file. |