Skip to content

Commit aab13f2

Browse files
committed
Do not auto-update exclusions when changing dependency coordinates
ChangeDependencyGroupIdAndArtifactId previously called ChangeExclusion to rename all exclusions matching the old coordinates to the new ones. This is incorrect because exclusions exist to block OLD transitive dependencies that other libraries may still pull in. Changing the exclusion from the old to the new coordinates means the old vulnerable artifact is no longer blocked. A stale exclusion (excluding something no longer pulled in transitively) is harmless, but an incorrect exclusion (no longer blocking a vulnerable transitive dependency) causes real problems.
1 parent 2825f94 commit aab13f2

2 files changed

Lines changed: 7 additions & 12 deletions

File tree

rewrite-maven/src/main/java/org/openrewrite/maven/ChangeDependencyGroupIdAndArtifactId.java

Lines changed: 1 addition & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -122,8 +122,7 @@ public String getInstanceNameSuffix() {
122122
}
123123

124124
String description = "Change a Maven dependency coordinates. The `newGroupId` or `newArtifactId` **MUST** be different from before. " +
125-
"Matching `<dependencyManagement>` coordinates are also updated if a `newVersion` or `versionPattern` is provided. " +
126-
"Exclusions that reference the old dependency coordinates will also be updated to match the new coordinates.";
125+
"Matching `<dependencyManagement>` coordinates are also updated if a `newVersion` or `versionPattern` is provided.";
127126

128127
@Override
129128
public Validated<Object> validate() {
@@ -270,12 +269,6 @@ public Xml visitDocument(Xml.Document document, ExecutionContext ctx) {
270269
newArtifactId,
271270
newVersion, versionPattern).getVisitor());
272271
}
273-
// Update any exclusions that reference the old coordinates
274-
if (newGroupId != null || newArtifactId != null) {
275-
doAfterVisit(new ChangeExclusion(
276-
oldGroupId, oldArtifactId,
277-
newGroupId, newArtifactId).getVisitor());
278-
}
279272
return super.visitDocument(document, ctx);
280273
}
281274

rewrite-maven/src/test/java/org/openrewrite/maven/ChangeDependencyGroupIdAndArtifactIdTest.java

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -3489,16 +3489,18 @@ void versionNotDroppedWhenSwaggerMigratedFirst() {
34893489

34903490
@Issue("https://github.com/moderneinc/customer-requests/issues/1330")
34913491
@Test
3492-
void exclusionUpdatedWhenDependencyGroupIdChanges() {
3493-
// When changing a dependency's groupId/artifactId, any exclusions that match
3494-
// the old coordinates should be updated to match the new coordinates.
3492+
void exclusionNotUpdatedWhenDependencyGroupIdChanges() {
3493+
// When changing a dependency's groupId/artifactId, exclusions that match
3494+
// the old coordinates should NOT be updated. The exclusion exists to block
3495+
// the old transitive dependency, and other libraries may still depend on
3496+
// the old artifact transitively.
34953497
rewriteRun(
34963498
spec -> spec.recipe(new ChangeDependencyGroupIdAndArtifactId(
34973499
"com.fasterxml.jackson.jaxrs",
34983500
"jackson-jaxrs-json-provider",
34993501
"com.fasterxml.jackson.jakarta.rs",
35003502
"jackson-jakarta-rs-json-provider",
3501-
"2.x",
3503+
"2.18.x",
35023504
null
35033505
)),
35043506
pomXml(

0 commit comments

Comments
 (0)