diff --git a/maven-model-builder/src/main/java/org/apache/maven/model/building/DefaultModelBuilder.java b/maven-model-builder/src/main/java/org/apache/maven/model/building/DefaultModelBuilder.java index 3bfcdbe4c818..704557951342 100644 --- a/maven-model-builder/src/main/java/org/apache/maven/model/building/DefaultModelBuilder.java +++ b/maven-model-builder/src/main/java/org/apache/maven/model/building/DefaultModelBuilder.java @@ -1812,7 +1812,7 @@ private DependencyManagement loadDependencyManagement( // Dependency excluded from import. List 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 @@ private DependencyManagement loadDependencyManagement( return importMgmt != null ? new DependencyManagement(importMgmt) : null; } + private static org.apache.maven.api.model.Dependency addExclusions( + org.apache.maven.api.model.Dependency candidate, List 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());