[MNG-8132] Fix BOM dependency exclusions (#1622)

The original patch from MNG-5600 had not been ported to the new model builder
This commit is contained in:
Guillaume Nodet 2024-08-11 00:42:29 +02:00 committed by GitHub
parent 4369fa8dff
commit 182b87c246
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
1 changed files with 7 additions and 1 deletions

View File

@ -1288,7 +1288,7 @@ public class DefaultModelBuilder implements ModelBuilder {
// Dependency excluded from import.
List<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);
}
@ -1296,6 +1296,12 @@ public class DefaultModelBuilder implements ModelBuilder {
return importMgmt;
}
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, Dependency candidate) {
return match(exclusion.getGroupId(), candidate.getGroupId())
&& match(exclusion.getArtifactId(), candidate.getArtifactId());