Skip to content

Commit

Permalink
[MNG-8118] Merge BOM exclusions instead of overwriting (#1504)
Browse files Browse the repository at this point in the history
  • Loading branch information
gnodet authored May 13, 2024
1 parent ba52bfe commit 0564480
Showing 1 changed file with 7 additions and 1 deletion.
Original file line number Diff line number Diff line change
Expand Up @@ -1812,14 +1812,20 @@ private DependencyManagement loadDependencyManagement(
// Dependency excluded from import.
List<org.apache.maven.api.model.Dependency> dependencies = importMgmt.getDependencies().stream()
.filter(candidate -> exclusions.stream().noneMatch(exclusion -> match(exclusion, candidate)))
.map(candidate -> candidate.withExclusions(exclusions))
.map(candidate -> addExclusions(candidate, exclusions))
.collect(Collectors.toList());
importMgmt = importMgmt.withDependencies(dependencies);
}

return importMgmt != null ? new DependencyManagement(importMgmt) : null;
}

private static org.apache.maven.api.model.Dependency addExclusions(
org.apache.maven.api.model.Dependency candidate, List<Exclusion> exclusions) {
return candidate.withExclusions(Stream.concat(candidate.getExclusions().stream(), exclusions.stream())
.toList());
}

private boolean match(Exclusion exclusion, org.apache.maven.api.model.Dependency candidate) {
return match(exclusion.getGroupId(), candidate.getGroupId())
&& match(exclusion.getArtifactId(), candidate.getArtifactId());
Expand Down

0 comments on commit 0564480

Please sign in to comment.