← All recipes
Open source

Change Maven parent

Recipe IDorg.openrewrite.maven.ChangeParentPom
Artifactorg.openrewrite:rewrite-maven

Change 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.

Single recipeApache 2.0

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.0

Options

NameTypeDescription
oldGroupIdrequiredStringThe group ID of the Maven parent pom to be changed away from.
e.g. org.springframework.boot
newGroupIdStringThe 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
oldArtifactIdrequiredStringThe artifact ID of the maven parent pom to be changed away from.
e.g. spring-boot-starter-parent
newArtifactIdStringThe 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
newVersionrequiredStringAn exact version number or node-style semver selector used to select the version number.
e.g. 29.X
oldRelativePathStringThe 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
newRelativePathStringNew relative path attribute for parent lookup.
e.g. ../pom.xml
versionPatternStringAllows 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
allowVersionDowngradesBooleanIf 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.
exceptListAccepts 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