[MNG-8118] Merge BOM exclusions instead of overwriting (#1504)

This commit is contained in:
Guillaume Nodet 2024-05-13 08:24:14 +02:00 committed by GitHub
parent ba52bfe600
commit 0564480440
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
1 changed files with 7 additions and 1 deletions

View File

@ -1812,7 +1812,7 @@ public class DefaultModelBuilder implements ModelBuilder {
// 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);
}
@ -1820,6 +1820,12 @@ public class DefaultModelBuilder implements ModelBuilder {
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());