Change Gradle or Maven dependency
org.openrewrite.java.dependencies.ChangeDependency
Change the group ID, artifact ID, and/or the version of a specified Gradle or Maven dependency.
Recipe source
GitHub, Issue Tracker, Maven Central
This recipe is available under the Apache License Version 2.0.
Options
| Type | Name | Description | Example |
|---|---|---|---|
String | oldGroupId | The old group ID to replace. The group ID is the first part of a dependency coordinate 'com.google.guava:guava:VERSION'. Supports glob expressions. | org.openrewrite.recipe |
String | oldArtifactId | The old artifact ID to replace. The artifact ID is the second part of a dependency coordinate 'com.google.guava:guava:VERSION'. Supports glob expressions. | rewrite-testing-frameworks |
String | newGroupId | Optional. The new group ID to use. Defaults to the existing group ID. | corp.internal.openrewrite.recipe |
String | newArtifactId | Optional. The new artifact ID to use. Defaults to the existing artifact ID. | rewrite-testing-frameworks |
String | newVersion | Optional. An exact version number or node-style semver selector used to select the version number. | 29.X |
String | versionPattern | Optional. Allows version selection to be extended beyond the original Node Semver semantics. So for example,Setting 'version' to "25-29" can be paired with a metadata pattern of "-jre" to select Guava 29.0-jre | -jre |
Boolean | overrideManagedVersion | Optional. If the new dependency has a managed version, this flag can be used to explicitly set the version on the dependency. The default for this flag is false. | |
Boolean | changeManagedDependency | Optional. Also update the dependency management section. The default for this flag is true. |
Used by
This recipe is used as part of the following composite recipes:
- Add explicit Common Annotations dependencies
- Add explicit JAX-WS dependencies
- Add explicit JAXB API dependencies
- Change
com.datastax.osstoorg.apache.cassandra - Change v1 Maven/Gradle dependencies to v2
- Migrate Apache Commons Logging 1.x to SLF4J 1.x
- Migrate Bouncy Castle from
jdk15ontojdk15to18for Java < 8 - Migrate Bouncy Castle to
jdk18on - Migrate Fest 2.x to AssertJ
- Migrate Hibernate Types to Hypersistence Utils 6.0
- Migrate Hibernate Types to Hypersistence Utils 6.2
- Migrate Hibernate Types to Hypersistence Utils 6.3
- Migrate Hibernate dependencies to 6.0.x
- Migrate Jackson from javax to jakarta namespace
- Migrate Jackson from javax to jakarta namespace
- Migrate Log4j 1.x to Log4j 2.x
- Migrate Log4j to SLF4J
- Migrate Okio dependencies to 3.x
- Migrate SAP cloud foundry logging support to Spring Boot 3.x
- Migrate SLF4J to Log4j 2.x API
- Migrate Spring Cloud Sleuth 3.1 to Micrometer Tracing 1.0
- Migrate Tag Libraries to 2.0 (Jakarta EE 9)
- Migrate
cucumber-java8tocucumber-java - Migrate com.intellij:annotations to org.jetbrains:annotations
- Migrate database drivers to Quarkus JDBC extensions
- Migrate dependencies from Jackson Codehaus (legacy) to FasterXML
- Migrate deprecated
javaee-apidependencies tojakarta.platform - Migrate deprecated
javax.activationpackages tojakarta.activation - Migrate deprecated
javax.activationpackages tojakarta.activation - Migrate deprecated
javax.annotationpackages tojakarta.annotation - 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 Spring Boot 1.x to 2.0
- Migrate from Swagger to OpenAPI
- Migrate javax.javaee-web-api to jakarta.jakartaee-web-api (Jakarta EE 9)
- Migrate javax.mvc to 2.0 (Jakarta EE 9)
- Migrate rider-spring (JUnit4) to rider-junit5 (JUnit5)
- Migrate thymeleaf dependencies to Spring Boot 3.x
- Migrate to Hibernate Validator 8.0.x
- Migrate to Hibernate for Jakarta EE 9
- Migrate to HtmlUnit 3.x
- Migrate to JavaEE8
- Migrate to New Spring Cloud Gateway Modules and Starters
- Migrate to Spring Boot 3.4
- 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
- Migrates to Apache POI 3.17
- Mitigation of Java XML Bind Deprecation in Java 11 vs WebLogic 14.1.2
- Mockito 3.x migration from 1.x
- Mockito 4 to 5.x upgrade only
- Modernize a Jenkins plugin to the latest recommended versions
- Relocate
org.apache.commons:commons-iotocommons-io:commons-io - Rename Testcontainers dependencies
- Replace Derby driver with Quarkus JDBC Derby
- Replace H2 driver with Quarkus JDBC H2
- Update Apache Commons Email to Email2 for Jakarta
- Update Apache Commons FileUpload2 package for EE10
- Update Jetty9 to Jetty12
- Update RestLet to 2.6.0
- Upgrade Jackson 2.x dependencies to 3.x
- Upgrade Struts 6.0 dependencies
- Upgrade dependencies to Spring Cloud 2022
- Upgrade to Cucumber-JVM 2.x
- Upgrade to Spring Boot 2.5
- Upgrade to SpringDoc 2.1
- Use Arquillian JUnit 5 Extension
- Use Byteman JUnit 5 dependency
- Use Jakarta Swagger Artifacts
- Use OkHttp 3 MockWebServer for JUnit 5
- Use XMLUnit Legacy for JUnit 5
- io.quarkus.updates.core.quarkus30.JavaxToJakartaAdditionalMigration
- io.quarkus.updates.core.quarkus33.GraalVMSubstitutionsArtifact
- io.quarkus.updates.core.quarkus36.JaegerSmallRyeOpenTracing
- io.quarkus.updates.core.quarkus37.HibernateSearchOutboxPolling
- io.quarkus.updates.core.quarkus37.ResteasyClientRenaming
- io.quarkus.updates.core.quarkus383.GraalSDK
- io.quarkus.updates.core.quarkus39.GraalSDK
- io.quarkus.updates.core.quarkus39.Relocations
Example
Parameters
| Parameter | Value |
|---|---|
| oldGroupId | commons-lang |
| oldArtifactId | commons-lang |
| newGroupId | org.apache.commons |
| newArtifactId | commons-lang3 |
| newVersion | 3.11.x |
| versionPattern | null |
| overrideManagedVersion | null |
| changeManagedDependency | null |
- build.gradle
- Diff
Before
plugins {
id "java-library"
}
repositories {
mavenCentral()
}
dependencies {
implementation "commons-lang:commons-lang:2.6"
}
After
plugins {
id "java-library"
}
repositories {
mavenCentral()
}
dependencies {
implementation "org.apache.commons:commons-lang3:3.11"
}
--- build.gradle
+++ build.gradle
@@ -10,1 +10,1 @@
dependencies {
- implementation "commons-lang:commons-lang:2.6"
+ implementation "org.apache.commons:commons-lang3:3.11"
}
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.ChangeDependencyExample.
Here's how you can define and customize such a recipe within your rewrite.yml:
---
type: specs.openrewrite.org/v1beta/recipe
name: com.yourorg.ChangeDependencyExample
displayName: Change Gradle or Maven dependency example
recipeList:
- org.openrewrite.java.dependencies.ChangeDependency:
oldGroupId: org.openrewrite.recipe
oldArtifactId: rewrite-testing-frameworks
newGroupId: corp.internal.openrewrite.recipe
newArtifactId: rewrite-testing-frameworks
newVersion: 29.X
versionPattern: '-jre'
Now that com.yourorg.ChangeDependencyExample has been defined, activate it and take a dependency on org.openrewrite.recipe:rewrite-java-dependencies:1.44.0 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.ChangeDependencyExample")
setExportDatatables(true)
}
repositories {
mavenCentral()
}
dependencies {
rewrite("org.openrewrite.recipe:rewrite-java-dependencies:1.44.0")
}
- 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.ChangeDependencyExample</recipe>
</activeRecipes>
</configuration>
<dependencies>
<dependency>
<groupId>org.openrewrite.recipe</groupId>
<artifactId>rewrite-java-dependencies</artifactId>
<version>1.44.0</version>
</dependency>
</dependencies>
</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 ChangeDependency --recipe-option "oldGroupId=org.openrewrite.recipe" --recipe-option "oldArtifactId=rewrite-testing-frameworks" --recipe-option "newGroupId=corp.internal.openrewrite.recipe" --recipe-option "newArtifactId=rewrite-testing-frameworks" --recipe-option "newVersion=29.X" --recipe-option "versionPattern='-jre'"
If the recipe is not available locally, then you can install it using:
mod config recipes jar install org.openrewrite.recipe:rewrite-java-dependencies:1.44.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. 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. |
| 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. |