diff --git a/rewrite-maven/src/main/java/org/openrewrite/maven/ChangeDependencyGroupIdAndArtifactId.java b/rewrite-maven/src/main/java/org/openrewrite/maven/ChangeDependencyGroupIdAndArtifactId.java
index dc40767039f..b8196b41787 100755
--- a/rewrite-maven/src/main/java/org/openrewrite/maven/ChangeDependencyGroupIdAndArtifactId.java
+++ b/rewrite-maven/src/main/java/org/openrewrite/maven/ChangeDependencyGroupIdAndArtifactId.java
@@ -203,7 +203,7 @@ public Xml visitTag(Xml.Tag tag, ExecutionContext ctx) {
// Otherwise, change the version to the new value.
t = changeChildTagValue(t, "version", resolvedNewVersion, ctx);
}
- } else if (configuredToOverrideManageVersion || !newDependencyManaged && !(oldDependencyManaged && configuredToChangeManagedDependency)) {
+ } else if (configuredToOverrideManageVersion || !newDependencyManaged) {
//If the version is not present, add the version if we are explicitly overriding a managed version or if no managed version exists.
Xml.Tag newVersionTag = Xml.Tag.build("" + resolvedNewVersion + "");
//noinspection ConstantConditions
diff --git a/rewrite-maven/src/main/java/org/openrewrite/maven/ChangeManagedDependencyGroupIdAndArtifactId.java b/rewrite-maven/src/main/java/org/openrewrite/maven/ChangeManagedDependencyGroupIdAndArtifactId.java
index 6fd50b1a19a..da0389461af 100644
--- a/rewrite-maven/src/main/java/org/openrewrite/maven/ChangeManagedDependencyGroupIdAndArtifactId.java
+++ b/rewrite-maven/src/main/java/org/openrewrite/maven/ChangeManagedDependencyGroupIdAndArtifactId.java
@@ -167,6 +167,7 @@ public Xml.Tag visitTag(Xml.Tag tag, ExecutionContext ctx) {
}
if (changed) {
maybeUpdateModel();
+ doAfterVisit(new RemoveRedundantDependencyVersions(null, null, null, null).getVisitor());
}
}
return t;
diff --git a/rewrite-maven/src/test/java/org/openrewrite/maven/ChangeDependencyGroupIdAndArtifactIdTest.java b/rewrite-maven/src/test/java/org/openrewrite/maven/ChangeDependencyGroupIdAndArtifactIdTest.java
index 22fe9af6951..aca6d239d9d 100644
--- a/rewrite-maven/src/test/java/org/openrewrite/maven/ChangeDependencyGroupIdAndArtifactIdTest.java
+++ b/rewrite-maven/src/test/java/org/openrewrite/maven/ChangeDependencyGroupIdAndArtifactIdTest.java
@@ -381,6 +381,71 @@ void managedToUnmanagedWithoutChangeManagedDependency() {
);
}
+ @Test
+ void managedToUnmanagedExternalizedDepMgmt() {
+ rewriteRun(
+ spec -> spec.recipe(new ChangeDependencyGroupIdAndArtifactId(
+ "org.springframework.cloud",
+ "spring-cloud-starter-sleuth",
+ "io.micrometer",
+ "micrometer-tracing-bridge-brave",
+ "1.0.12",
+ null
+ )),
+ pomXml(
+ """
+
+
+
+
+ org.springframework.cloud
+ spring-cloud-dependencies
+ 2021.0.0
+ bom
+ import
+
+
+
+ com.mycompany.app
+ sample
+ 1
+
+
+ org.springframework.cloud
+ spring-cloud-starter-sleuth
+
+
+
+ """,
+ """
+
+
+
+
+ org.springframework.cloud
+ spring-cloud-dependencies
+ 2021.0.0
+ bom
+ import
+
+
+
+ com.mycompany.app
+ sample
+ 1
+
+
+ io.micrometer
+ micrometer-tracing-bridge-brave
+ 1.0.12
+
+
+
+ """
+ )
+ );
+ }
+
@Test
void unmanagedToManaged() {
rewriteRun(
@@ -573,6 +638,71 @@ void unmanagedToManagedWithOverrideManagedVersionNull() {
);
}
+ @Test
+ void unmanagedToManagedExternalizedDepMgmt() {
+ rewriteRun(
+ spec -> spec.recipe(new ChangeDependencyGroupIdAndArtifactId(
+ "io.micrometer",
+ "micrometer-tracing-bridge-brave",
+ "org.springframework.cloud",
+ "spring-cloud-starter-sleuth",
+ "2021.0.0",
+ null
+ )),
+ pomXml(
+ """
+
+
+
+
+ org.springframework.cloud
+ spring-cloud-dependencies
+ 2021.0.0
+ bom
+ import
+
+
+
+ com.mycompany.app
+ sample
+ 1
+
+
+ io.micrometer
+ micrometer-tracing-bridge-brave
+ 1.0.12
+
+
+
+ """,
+ """
+
+
+
+
+ org.springframework.cloud
+ spring-cloud-dependencies
+ 2021.0.0
+ bom
+ import
+
+
+
+ com.mycompany.app
+ sample
+ 1
+
+
+ org.springframework.cloud
+ spring-cloud-starter-sleuth
+
+
+
+ """
+ )
+ );
+ }
+
@Test
void changeOnlyArtifactId() {
rewriteRun(