Skip to content

[MNG-5600] Dependency management import should support exclusions.#148

Closed
ChristianSchulte wants to merge 1 commit intoapache:masterfrom
ChristianSchulte:MNG-5600
Closed

[MNG-5600] Dependency management import should support exclusions.#148
ChristianSchulte wants to merge 1 commit intoapache:masterfrom
ChristianSchulte:MNG-5600

Conversation

@ChristianSchulte
Copy link
Copy Markdown
Contributor

No description provided.

@ChristianSchulte
Copy link
Copy Markdown
Contributor Author

Corresponding IT pull request.

@RayzorFlash
Copy link
Copy Markdown

@ChristianSchulte - Any update on when this can/will be merged?? I'm unfamiliar with the maven contribution process

@alex1989hu
Copy link
Copy Markdown

alex1989hu commented Oct 13, 2019

@olamy @rfscholte - Could we get this patch being merged? If any help is needed don't hesitate to ping me.

Here is @ChristianSchulte's updated patch without conflict:

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 f981944f940fcbc912959752d3cff4bc1586519f..2a65bbe9ac14a01dac0c49d900c3fbeef052f6a3 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
@@ -27,6 +27,7 @@
 import org.apache.maven.model.Build;
 import org.apache.maven.model.Dependency;
 import org.apache.maven.model.DependencyManagement;
+import org.apache.maven.model.Exclusion;
 import org.apache.maven.model.InputLocation;
 import org.apache.maven.model.InputSource;
 import org.apache.maven.model.Model;
@@ -1316,7 +1317,40 @@ private void importDependencyManagement( Model model, ModelBuildingRequest reque
                     importMgmt = new DependencyManagement();
                 }
 
-                putCache( request.getModelCache(), groupId, artifactId, version, ModelCacheTag.IMPORT, importMgmt );
+                // [MNG-5600] Dependency management import should support exclusions.
+                if ( !dependency.getExclusions().isEmpty() )
+                {
+                    for ( final Exclusion exclusion : dependency.getExclusions() )
+                    {
+                        if ( exclusion.getGroupId() != null && exclusion.getArtifactId() != null )
+                        {
+                            for ( final Iterator<Dependency> dependencies = importMgmt.getDependencies().iterator();
+                                dependencies.hasNext(); )
+                            {
+                                final Dependency candidate = dependencies.next();
+
+                                if ( ( exclusion.getGroupId().equals( "*" )
+                                    || exclusion.getGroupId().equals( candidate.getGroupId() ) )
+                                    && ( exclusion.getArtifactId().equals( "*" )
+                                    || exclusion.getArtifactId().equals( candidate.getArtifactId() ) ) )
+                                {
+                                    // Dependency excluded from import.
+                                    dependencies.remove();
+                                }
+                            }
+                        }
+                    }
+
+                    for ( final Dependency includedDependency : importMgmt.getDependencies() )
+                    {
+                        includedDependency.getExclusions().addAll( dependency.getExclusions() );
+                    }
+                }
+                else
+                {
+                    // Only dependency managements without exclusion processing applied can be cached.
+                    putCache( request.getModelCache(), groupId, artifactId, version, ModelCacheTag.IMPORT, importMgmt );
+                }
             }
 
             if ( importMgmts == null )

@olamy
Copy link
Copy Markdown
Member

olamy commented Oct 13, 2019

@alex1989hu please provide another pr

pzygielo pushed a commit to pzygielo/maven that referenced this pull request Jan 4, 2023
… dependency in profile which is managed by <dependencyManagement> (apache#155)

* Fixes apache#145, apache#148 add codes to parse the <version> for the dependency in profile which is managed by <dependencyManagement>

* remove redundant code

* add empty line at the end of files

* remove profile-with-deps-inherit-parent-depMgmt-ci test

* consolidate two blocks of code change into createCleanPom method

* restore import change

* restore import change

* add test profile-with-deps-inherit-parent-depMgmt-flatten-dep-all-oss

* change test profile-with-deps-inherit-parent-depMgmt-flatten-dep-all-oss to profile-with-deps-inherit-parent-depMgmt-flatten-dep-all-oss-bom

* code style fix

* fix indents and licenses declaration in verify.groovy

* set scope as compile and optional as false if not specified

* fix scope and optional - code style

Co-authored-by: yangnuoyu <yangnuoyu@penguin>
@gnodet gnodet closed this Jun 15, 2023
@jira-importer
Copy link
Copy Markdown

Resolve #6722

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

6 participants