Hiteshsai007 commented on code in PR #13649:
URL: https://github.com/apache/maven/pull/13649#discussion_r4324548626


##########
impl/maven-impl/src/main/java/org/apache/maven/impl/DefaultDependencyResolver.java:
##########
@@ -182,6 +192,51 @@ public DependencyResolverResult collect(@Nonnull 
DependencyResolverRequest reque
         }
     }
 
+    /**
+     * Applies dependency management to dependencies supplied outside the 
project model. Resolver applies managed
+     * dependencies only below the root's direct dependencies, while project 
model building normally performs this
+     * merge before resolution. Dependencies supplied by a plugin therefore 
need the same merge here.
+     */
+    static List<org.eclipse.aether.graph.Dependency> applyDependencyManagement(
+            Collection<org.eclipse.aether.graph.Dependency> dependencies,
+            Collection<org.eclipse.aether.graph.Dependency> 
managedDependencies) {
+        Map<String, org.eclipse.aether.graph.Dependency> managed = new 
HashMap<>();
+        for (org.eclipse.aether.graph.Dependency dependency : 
managedDependencies) {
+            managed.put(dependencyKey(dependency), dependency);
+        }
+
+        List<org.eclipse.aether.graph.Dependency> result = new 
ArrayList<>(dependencies.size());
+        for (org.eclipse.aether.graph.Dependency dependency : dependencies) {
+            org.eclipse.aether.graph.Dependency management = 
managed.get(dependencyKey(dependency));
+            if (management == null) {
+                result.add(dependency);
+                continue;
+            }
+
+            org.eclipse.aether.artifact.Artifact artifact = 
dependency.getArtifact();
+            if (artifact.getVersion().isEmpty()) {
+                artifact = 
artifact.setVersion(management.getArtifact().getVersion());
+            }
+            String scope = dependency.getScope();
+            if (scope == null || scope.isEmpty()) {

Review Comment:
   Fixed in 8dbc194960: removed the unreachable null check and now test scope 
emptiness directly.



##########
impl/maven-impl/src/main/java/org/apache/maven/impl/DefaultDependencyResolver.java:
##########
@@ -127,7 +129,8 @@ public DependencyResolverResult collect(@Nonnull 
DependencyResolverRequest reque
                 Project project = request.getProject().get();
                 rootArtifact = project.getPomArtifact();
                 root = null;
-                dependencies = project.getDependencies();
+                dependencies =
+                        request.getDependencies().isEmpty() ? 
project.getDependencies() : request.getDependencies();

Review Comment:
   Addressed in 8dbc194960: added a code comment documenting that 
caller-supplied dependencies take precedence for plugin-specific 
project-context resolution.



##########
api/maven-api-core/src/main/java/org/apache/maven/api/services/DependencyResolverRequest.java:
##########
@@ -155,6 +155,50 @@ static DependencyResolverRequest build(Session session, 
RequestType requestType,
                 .build();
     }
 
+    @Nonnull
+    static DependencyResolverRequest build(
+            Session session, RequestType requestType, Project project, 
DependencyCoordinates dependency) {
+        return build(session, requestType, project, dependency, 
PathScope.MAIN_RUNTIME);

Review Comment:
   Addressed in 8dbc194960: documented the MAIN_RUNTIME default and the 
scope-taking alternative on both project-context convenience methods and 
request builders.



-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: [email protected]

For queries about this service, please contact Infrastructure at:
[email protected]

Reply via email to