org.openrewrite.maven.UpgradeDependencyVersion
Upgrade the version of a dependency by specifying a group and (optionally) an artifact using Node Semver advanced range selectors, allowing more precise control over version updates to patch or minor releases.
GitHub, Issue Tracker, Maven Central
- groupId: org.openrewrite
- artifactId: rewrite-maven
- version: 8.1.3
Type | Name | Description |
---|---|---|
String |
groupId | The first part of a dependency coordinate com.google.guava:guava:VERSION . This can be a glob expression. |
String |
artifactId | The second part of a dependency coordinate com.google.guava:guava:VERSION . This can be a glob expression. |
String |
newVersion | An exact version number or node-style semver selector used to select the version number. |
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 |
Boolean |
overrideManagedVersion | Optional. This flag can be set to explicitly override a managed dependency's version. The default for this flag is false . |
List |
retainVersions | Optional. 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 |
Data Tables (Only available on the Moderne platform)
Attempts to resolve maven metadata that failed.
Column Name | Description |
---|
Parameter | Value |
---|---|
groupId | io.dropwizard.metrics |
artifactId | metrics-annotation |
newVersion | 4.2.9 |
versionPattern | null |
overrideManagedVersion | true |
retainVersions | null |
{% tabs %} {% tab title="pom.xml" %}
{% code title="pom.xml" %}
<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 https://maven.apache.org/xsd/maven-4.0.0.xsd">
<modelVersion>4.0.0</modelVersion>
<groupId>com.example</groupId>
<artifactId>explicit-deps-app</artifactId>
<version>0.0.1-SNAPSHOT</version>
<name>explicit-deps-app</name>
<description>explicit-deps-app</description>
<properties>
<java.version>17</java.version>
<maven.compiler.source>17</maven.compiler.source>
<maven.compiler.target>17</maven.compiler.target>
</properties>
<repositories>
<repository>
<id>spring-milestone</id>
<url>https://repo.spring.io/milestone</url>
<snapshots>
<enabled>false</enabled>
</snapshots>
</repository>
</repositories>
<dependencyManagement>
<dependencies>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-dependencies</artifactId>
<version>2.4.0</version>
<type>pom</type>
<scope>import</scope>
</dependency>
</dependencies>
</dependencyManagement>
<dependencies>
<dependency>
<groupId>io.dropwizard.metrics</groupId>
<artifactId>metrics-annotation</artifactId>
</dependency>
</dependencies>
</project>
{% endcode %}
{% code title="pom.xml" %}
<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 https://maven.apache.org/xsd/maven-4.0.0.xsd">
<modelVersion>4.0.0</modelVersion>
<groupId>com.example</groupId>
<artifactId>explicit-deps-app</artifactId>
<version>0.0.1-SNAPSHOT</version>
<name>explicit-deps-app</name>
<description>explicit-deps-app</description>
<properties>
<java.version>17</java.version>
<maven.compiler.source>17</maven.compiler.source>
<maven.compiler.target>17</maven.compiler.target>
</properties>
<repositories>
<repository>
<id>spring-milestone</id>
<url>https://repo.spring.io/milestone</url>
<snapshots>
<enabled>false</enabled>
</snapshots>
</repository>
</repositories>
<dependencyManagement>
<dependencies>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-dependencies</artifactId>
<version>2.4.0</version>
<type>pom</type>
<scope>import</scope>
</dependency>
</dependencies>
</dependencyManagement>
<dependencies>
<dependency>
<groupId>io.dropwizard.metrics</groupId>
<artifactId>metrics-annotation</artifactId>
<version>4.2.9</version>
</dependency>
</dependencies>
</project>
{% endcode %}
{% endtab %} {% tab title="Diff" %} {% code %}
--- pom.xml
+++ pom.xml
@@ -38,0 +38,1 @@
<groupId>io.dropwizard.metrics</groupId>
<artifactId>metrics-annotation</artifactId>
+ <version>4.2.9</version>
</dependency>
{% endcode %} {% endtab %} {% endtabs %}
Parameter | Value |
---|---|
groupId | org.springframework.cloud |
artifactId | spring-cloud-config-dependencies |
newVersion | 3.1.4 |
versionPattern | null |
overrideManagedVersion | true |
retainVersions | Collections.singletonList("com.jcraft:jsch") |
{% tabs %} {% tab title="pom.xml" %}
{% code title="pom.xml" %}
<?xml version="1.0" encoding="UTF-8"?>
<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
<modelVersion>4.0.0</modelVersion>
<groupId>org.sample</groupId>
<artifactId>sample</artifactId>
<version>1.0.0</version>
<dependencyManagement>
<dependencies>
<dependency>
<groupId>org.springframework.cloud</groupId>
<artifactId>spring-cloud-config-dependencies</artifactId>
<version>3.1.2</version>
<type>pom</type>
<scope>import</scope>
</dependency>
</dependencies>
</dependencyManagement>
<dependencies>
<dependency>
<groupId>com.jcraft</groupId>
<artifactId>jsch</artifactId>
<version>0.1.55</version>
</dependency>
</dependencies>
</project>
{% endcode %}
{% code title="pom.xml" %}
<?xml version="1.0" encoding="UTF-8"?>
<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
<modelVersion>4.0.0</modelVersion>
<groupId>org.sample</groupId>
<artifactId>sample</artifactId>
<version>1.0.0</version>
<dependencyManagement>
<dependencies>
<dependency>
<groupId>org.springframework.cloud</groupId>
<artifactId>spring-cloud-config-dependencies</artifactId>
<version>3.1.4</version>
<type>pom</type>
<scope>import</scope>
</dependency>
</dependencies>
</dependencyManagement>
<dependencies>
<dependency>
<groupId>com.jcraft</groupId>
<artifactId>jsch</artifactId>
<version>0.1.55</version>
</dependency>
</dependencies>
</project>
{% endcode %}
{% endtab %} {% tab title="Diff" %} {% code %}
--- pom.xml
+++ pom.xml
@@ -13,1 +13,1 @@
<groupId>org.springframework.cloud</groupId>
<artifactId>spring-cloud-config-dependencies</artifactId>
- <version>3.1.2</version>
+ <version>3.1.4</version>
<type>pom</type>
{% endcode %} {% endtab %} {% endtabs %}
This recipe has required configuration parameters. Recipes with required configuration parameters cannot be activated directly. 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:
{% code title="rewrite.yml" %}
---
type: specs.openrewrite.org/v1beta/recipe
name: com.yourorg.UpgradeDependencyVersionExample
displayName: Upgrade Maven dependency version example
recipeList:
- org.openrewrite.maven.UpgradeDependencyVersion:
groupId: com.fasterxml.jackson*
artifactId: jackson-module*
newVersion: 29.X
versionPattern: '-jre'
overrideManagedVersion: null
retainVersions: com.jcraft:jsch
{% endcode %}
Now that com.yourorg.UpgradeDependencyVersionExample
has been defined activate it in your build file:
{% tabs %}
{% tab title="Maven" %} {% code title="pom.xml" %}
<project>
<build>
<plugins>
<plugin>
<groupId>org.openrewrite.maven</groupId>
<artifactId>rewrite-maven-plugin</artifactId>
<version>5.2.4</version>
<configuration>
<activeRecipes>
<recipe>com.yourorg.UpgradeDependencyVersionExample</recipe>
</activeRecipes>
</configuration>
</plugin>
</plugins>
</build>
</project>
{% endcode %} {% endtab %} {% endtabs %}
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.