Upgrade Gradle or Maven dependency versions
org.openrewrite.java.dependencies.UpgradeDependencyVersion
For Gradle projects, upgrade the version of a dependency in a build.gradle
file. Supports updating dependency declarations of various forms: * String
notation: "group:artifact:version"
* Map
notation: group: 'group', name: 'artifact', version: 'version'
It is possible to update version numbers which are defined earlier in the same file in variable declarations. For Maven projects, upgrade the version of a dependency by specifying a group ID and (optionally) an artifact ID using Node Semver advanced range selectors, allowing more precise control over version updates to patch or minor releases.
Recipe source
GitHub, Issue Tracker, Maven Central
This recipe is available under the Apache License Version 2.0.
Options
Type | Name | Description | Example |
---|---|---|---|
String | groupId | The first part of a dependency coordinate com.google.guava:guava:VERSION . This can be a glob expression. | com.fasterxml.jackson* |
String | artifactId | The second part of a dependency coordinate com.google.guava:guava:VERSION . This can be a glob expression. | jackson-module* |
String | newVersion | 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. For Maven project only, This flag can be set to explicitly override a managed dependency's version. The default for this flag is false . | |
List | retainVersions | Optional. For Maven project only, accepts a list of GAVs. For each GAV, if it is a project direct dependency, and it is removed from dependency management after the changes from this recipe, then it will be retained with an explicit version. The version can be omitted from the GAV to use the old value from dependency management. | com.jcraft:jsch |
Used by
This recipe is used as part of the following composite recipes:
- Add explicit Inject dependencies
- Add explicit JAX-WS dependencies
- Add explicit JAXB API dependencies
- ArchUnit 0.x upgrade
- Jackson best practices
- Migrate Ehcache from javax to jakarta namespace
- Migrate Hibernate dependencies to 6.0.x
- Migrate Jakarta EE 9 api dependencies to Jakarta EE 10 versions
- Migrate Johnzon from javax to jakarta namespace
- Migrate Log4j to SLF4J
- Migrate Lombok to a Java 11 compatible version
- Migrate OkHttp dependencies to 4.x
- Migrate OkHttp dependencies to 5.x
- Migrate Okio dependencies to 3.x
- Migrate RestAssured from javax to jakarta namespace by upgrading to a version compatible with J2EE9
- Migrate deprecated
javaee-api
dependencies tojakarta.platform
- 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.decorator
packages tojakarta.decorator
- Migrate deprecated
javax.ejb
packages tojakarta.ejb
- Migrate deprecated
javax.el
packages tojakarta.el
- Migrate deprecated
javax.enterprise
packages tojakarta.enterprise
- Migrate deprecated
javax.faces
packages tojakarta.faces
- Migrate deprecated
javax.inject
packages tojakarta.inject
- Migrate deprecated
javax.interceptor
packages tojakarta.interceptor
- Migrate deprecated
javax.jms
packages tojakarta.jms
- Migrate deprecated
javax.json
packages tojakarta.json
- Migrate deprecated
javax.jws
packages tojakarta.jws
- Migrate deprecated
javax.mail
packages tojakarta.mail
- Migrate deprecated
javax.persistence
packages tojakarta.persistence
- Migrate deprecated
javax.resource
packages tojakarta.resource
- Migrate deprecated
javax.security.auth.message
packages tojakarta.security.auth.message
- Migrate deprecated
javax.security.enterprise
packages tojakarta.security.enterprise
- Migrate deprecated
javax.security.jacc
packages tojakarta.security.jacc
- Migrate deprecated
javax.servlet
packages tojakarta.servlet
- Migrate deprecated
javax.soap
packages tojakarta.soap
- Migrate deprecated
javax.transaction
packages tojakarta.transaction
- Migrate deprecated
javax.validation
packages tojakarta.validation
- Migrate deprecated
javax.websocket
packages tojakarta.websocket
- Migrate deprecated
javax.ws
packages tojakarta.ws
- Migrate deprecated
javax.xml.bind
packages tojakarta.xml.bind
- Migrate deprecated
javax.xml.ws
packages tojakarta.xml.ws
- Migrate from Spring Boot 1.x to 2.0
- Migrate to Hibernate 6.1.x
- Migrate to Hibernate 6.2.x
- Migrate to Hibernate 6.3.x
- Migrate to Hibernate 6.4.x
- Migrate to Hibernate 6.5.x
- Migrate to Hibernate 6.6.x
- Migrate to Hibernate 7.0.x
- Migrate to Hibernate for Jakarta EE 9
- Migrate to Java 17
- Migrate to LaunchDarkly 6.x
- Migrate to LaunchDarkly 7.x
- Migrate to Micrometer 1.13
- Migrate to Reactor 3.5
- Migrate to Scala 2.12.+
- Migrate to Spring Batch 5.0 from 4.3
- Migrate to Spring Boot 2.1
- Migrate to Spring Boot 2.2
- Migrate to Spring Boot 2.3
- Migrate to Spring Boot 2.4
- Migrate to Spring Boot 2.6
- Migrate to Spring Boot 2.7
- Migrate to Spring Boot 3.0
- Migrate to Spring Boot 3.1
- Migrate to Spring Boot 3.2
- Migrate to Spring Boot 3.3
- Migrate to Spring Boot 3.4
- Migrate to Spring Boot 3.5
- Migrate to Spring Framework 5.0
- Migrate to Spring Framework 5.1
- Migrate to Spring Framework 5.2
- Migrate to Spring Framework 5.3
- Migrate to Spring Framework 6.0
- Migrate to Spring Framework 6.1
- Migrate to Spring Framework 6.2 for WebLogic 15.1.1
- Migrate to Spring Framework 6.2
- Migrate to Spring Security 5.7
- Migrate to Spring Security 5.8
- Migrate to Spring Security 6.0
- Migrate to Spring Security 6.1
- Migrate to Spring Security 6.2
- Migrate to Spring Security 6.3
- Migrate to Spring Security 6.4
- Migrates from Jackson 2.x to Jackson 3.x
- Migrates from Netty 4.1.x to Netty 4.2.x
- Migrates to Apache POI 3.17
- Migrates to ApacheHttpClient 4.5.x
- Mockito 3.x migration from 1.x
- Mockito 4 to 5.x upgrade only
- Mockito 4.x upgrade
- OkHttp 3.x
MockWebServer
@Rule
To 4.xMockWebServer
- Prefer the Java 11 standard library instead of Guava
- Quarkus 2.x migration from Quarkus 1.x
- Testcontainers best practices
- Update Apache Shiro Dependencies to 2.0.x
- Update Eclipse Yasson Dependencies to 3.0.x
- Update EclipseLink Dependencies to 4.x
- Update GlassFish Jersey Dependencies to 3.1.x
- Update Jakarta EE Java Faces Dependencies to 4.0.x.
- Update Jakarta EE Java Faces Dependencies to 4.1.x
- Update Jakarta EE Platform Dependencies to 10.0.0
- Update Jakarta EE Platform Dependencies to 11.0.x
- Update Jakarta EE Platform Dependencies to 9.1.0
- Update Jakarta EE XML Web Services Dependencies for EE 10.
- Update Jakarta EE annotation Dependencies to 2.1.x.
- Update the WebLogic version to 14.1.2
- Update the WebLogic version to 15.1.1
- Upgrade Common open source libraries
- Upgrade Faces open source libraries
- Upgrade Faces open source libraries
- Upgrade Faces open source libraries
- Upgrade Faces open source libraries
- Upgrade Faces open source libraries
- Upgrade JaCoCo
- Upgrade Log4j 2.x dependency version
- Upgrade MyBatis to Spring Boot 2.0
- Upgrade MyBatis to Spring Boot 2.1
- Upgrade MyBatis to Spring Boot 2.2
- Upgrade MyBatis to Spring Boot 2.3
- Upgrade MyBatis to Spring Boot 2.4
- Upgrade MyBatis to Spring Boot 2.5
- Upgrade MyBatis to Spring Boot 2.6
- Upgrade MyBatis to Spring Boot 2.7
- Upgrade MyBatis to Spring Boot 3.0
- Upgrade MyBatis to Spring Boot 3.2
- Upgrade MyBatis to Spring Boot 3.4
- Upgrade Spring Cloud AWS to Spring Boot 3.4 compatible version
- Upgrade Spring Data BOM to 2024.1.x
- Upgrade Struts 6.0 dependencies
- Upgrade dependencies to Spring Cloud 2022
- Upgrade dependencies to Spring Cloud 2023
- Upgrade dependencies to Spring Cloud 2024
- Upgrade dependencies to Spring Cloud 2025
- Upgrade plugins to Java 21 compatible versions
- Upgrade to Cucumber-JVM 7.x
- Upgrade to Spring Boot 2.5
- Upgrade to SpringDoc 2.1
- Upgrade to SpringDoc 2.2
- Upgrade to SpringDoc 2.5
- Upgrade to SpringDoc 2.6
- Upgrade to SpringDoc 2.8
- Use wiremock extension
Example
Parameters
Parameter | Value |
---|---|
groupId | com.google.guava |
artifactId | guava |
newVersion | 30.x |
versionPattern | -jre |
overrideManagedVersion | null |
retainVersions | null |
- build.gradle
- Diff
Before
plugins {
id 'java-library'
}
repositories {
mavenCentral()
}
dependencies {
compileOnly 'com.google.guava:guava:29.0-jre'
runtimeOnly ('com.google.guava:guava:29.0-jre')
}
After
plugins {
id 'java-library'
}
repositories {
mavenCentral()
}
dependencies {
compileOnly 'com.google.guava:guava:30.1.1-jre'
runtimeOnly ('com.google.guava:guava:30.1.1-jre')
}
--- build.gradle
+++ build.gradle
@@ -10,2 +10,2 @@
dependencies {
- compileOnly 'com.google.guava:guava:29.0-jre'
- runtimeOnly ('com.google.guava:guava:29.0-jre')
+ compileOnly 'com.google.guava:guava:30.1.1-jre'
+ runtimeOnly ('com.google.guava:guava:30.1.1-jre')
}
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.UpgradeDependencyVersionExample
.
Here's how you can define and customize such a recipe within your rewrite.yml:
---
type: specs.openrewrite.org/v1beta/recipe
name: com.yourorg.UpgradeDependencyVersionExample
displayName: Upgrade Gradle or Maven dependency versions example
recipeList:
- org.openrewrite.java.dependencies.UpgradeDependencyVersion:
groupId: com.fasterxml.jackson*
artifactId: jackson-module*
newVersion: 29.X
versionPattern: '-jre'
retainVersions: com.jcraft:jsch
Now that com.yourorg.UpgradeDependencyVersionExample
has been defined, activate it and take a dependency on org.openrewrite.recipe:rewrite-java-dependencies:1.39.0
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.UpgradeDependencyVersionExample")
setExportDatatables(true)
}
repositories {
mavenCentral()
}
dependencies {
rewrite("org.openrewrite.recipe:rewrite-java-dependencies:1.39.0")
}
- 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.UpgradeDependencyVersionExample</recipe>
</activeRecipes>
</configuration>
<dependencies>
<dependency>
<groupId>org.openrewrite.recipe</groupId>
<artifactId>rewrite-java-dependencies</artifactId>
<version>1.39.0</version>
</dependency>
</dependencies>
</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 UpgradeDependencyVersion --recipe-option "groupId=com.fasterxml.jackson*" --recipe-option "artifactId=jackson-module*" --recipe-option "newVersion=29.X" --recipe-option "versionPattern='-jre'" --recipe-option "retainVersions=com.jcraft:jsch"
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.39.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. |
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. |