Skip to content

Commit

Permalink
RemoveManagedDependency can now remove bom imports
Browse files Browse the repository at this point in the history
  • Loading branch information
nmck257 committed Feb 14, 2024
1 parent 0c67bf2 commit ababd3e
Show file tree
Hide file tree
Showing 2 changed files with 42 additions and 2 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -78,8 +78,8 @@ private class RemoveManagedDependencyVisitor extends MavenIsoVisitor<ExecutionCo
public Xml.Tag visitTag(Xml.Tag tag, ExecutionContext ctx) {
if (isManagedDependencyTag(groupId, artifactId)) {
Scope checkScope = scope != null ? Scope.fromName(scope) : null;
ResolvedManagedDependency managedDependency = findManagedDependency(tag, checkScope);
if (managedDependency != null) {
boolean isBomImport = tag.getChildValue("scope").map("import"::equalsIgnoreCase).orElse(false);
if (isBomImport || findManagedDependency(tag, checkScope) != null) {
doAfterVisit(new RemoveContentVisitor<>(tag, true));
maybeUpdateModel();
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -217,4 +217,44 @@ void removeManagedDependencyWithScopeNonMatching() {
)
);
}

@Test
void removeBomImport() {
rewriteRun(
spec -> spec.recipe(new RemoveManagedDependency(
"io.micrometer",
"micrometer-bom",
null
)),
pomXml(
"""
<project>
<modelVersion>4.0.0</modelVersion>
<groupId>com.mycompany.app</groupId>
<artifactId>my-app</artifactId>
<version>1</version>
<dependencyManagement>
<dependencies>
<dependency>
<groupId>io.micrometer</groupId>
<artifactId>micrometer-bom</artifactId>
<version>1.9.9</version>
<scope>import</scope>
<type>bom</type>
</dependency>
</dependencies>
</dependencyManagement>
</project>
""",
"""
<project>
<modelVersion>4.0.0</modelVersion>
<groupId>com.mycompany.app</groupId>
<artifactId>my-app</artifactId>
<version>1</version>
</project>
"""
)
);
}
}

0 comments on commit ababd3e

Please sign in to comment.