You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@maven.apache.org by gn...@apache.org on 2024/05/13 06:24:20 UTC

(maven) branch master updated: [MNG-8118] Merge BOM exclusions instead of overwriting (#1504)

This is an automated email from the ASF dual-hosted git repository.

gnodet pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/maven.git


The following commit(s) were added to refs/heads/master by this push:
     new 0564480440 [MNG-8118] Merge BOM exclusions instead of overwriting (#1504)
0564480440 is described below

commit 056448044055292b9421d86b28564a1706c4c937
Author: Guillaume Nodet <gn...@gmail.com>
AuthorDate: Mon May 13 08:24:14 2024 +0200

    [MNG-8118] Merge BOM exclusions instead of overwriting (#1504)
---
 .../java/org/apache/maven/model/building/DefaultModelBuilder.java | 8 +++++++-
 1 file changed, 7 insertions(+), 1 deletion(-)

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 3bfcdbe4c8..7045579513 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 @@ 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());