Change Maven parent
Recipe ID
org.openrewrite.maven.ChangeParentPomArtifact
org.openrewrite:rewrite-mavenChange the parent pom of a Maven pom.xml by matching the existing parent via groupId and artifactId, and updating it to a new groupId, artifactId, version, and optional relativePath. Also updates the project to retain dependency management and properties previously inherited from the old parent that are no longer provided by the new parent. Removes redundant dependency versions already managed by the new parent.
Usage
You’ll need the Moderne CLI configured before running the command below.
mod run . --recipe org.openrewrite.maven.ChangeParentPom --recipe-option "oldGroupId=org.springframework.boot" --recipe-option "oldArtifactId=spring-boot-starter-parent" --recipe-option "newVersion=29.X"If the recipe isn’t available locally, install it with:
mod config recipes jar install org.openrewrite:rewrite-maven:8.88.0Options
| Name | Type | Description |
|---|---|---|
oldGroupIdrequired | String | The group ID of the Maven parent pom to be changed away from. e.g. org.springframework.boot |
newGroupId | String | The group ID of the new maven parent pom to be adopted. If this argument is omitted it defaults to the value of oldGroupId.e.g. org.springframework.boot |
oldArtifactIdrequired | String | The artifact ID of the maven parent pom to be changed away from. e.g. spring-boot-starter-parent |
newArtifactId | String | The artifact ID of the new maven parent pom to be adopted. If this argument is omitted it defaults to the value of oldArtifactId.e.g. spring-boot-starter-parent |
newVersionrequired | String | An exact version number or node-style semver selector used to select the version number. e.g. 29.X |
oldRelativePath | String | The relativePath of the maven parent pom to be changed away from. Use an empty String to match <relativePath />, use ../pom.xml to match the default value.e.g. ../../pom.xml |
newRelativePath | String | New relative path attribute for parent lookup. e.g. ../pom.xml |
versionPattern | String | 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 e.g. -jre |
allowVersionDowngrades | Boolean | If the new parent has the same group/artifact, this flag can be used to only upgrade the version if the target version is newer than the current. |
except | List | Accepts a list of GAVs that should be retained when calling RemoveRedundantDependencyVersions.e.g. com.jcraft:jsch |
Data tables
Structured output this recipe can produce.
- Maven metadata failuresAttempts to resolve maven metadata that failed.
org.openrewrite.maven.table.MavenMetadataFailures - Source files that had resultsSource files that were modified by the recipe run.
org.openrewrite.table.SourcesFileResults - Source files that had search resultsSearch results that were found during the recipe run.
org.openrewrite.table.SearchResults - Source files that errored on a recipeThe details of all errors produced by a recipe run.
org.openrewrite.table.SourcesFileErrors - Recipe performanceStatistics used in analyzing the performance of recipes.
org.openrewrite.table.RecipeRunStats