[ 
https://issues.apache.org/jira/browse/MASSEMBLY-1008?page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel&focusedCommentId=17811490#comment-17811490
 ] 

ASF GitHub Bot commented on MASSEMBLY-1008:
-------------------------------------------

slawekjaranowski commented on code in PR #166:
URL: 
https://github.com/apache/maven-assembly-plugin/pull/166#discussion_r1468436721


##########
src/main/java/org/apache/maven/plugins/assembly/artifact/DefaultDependencyResolver.java:
##########
@@ -158,14 +188,91 @@ void updateDependencySetResolutionRequirements(
 
             Set<Artifact> dependencyArtifacts = null;
             if (set.isUseTransitiveDependencies()) {
-                dependencyArtifacts = project.getArtifacts();
+                try {
+                    // we need resolve project again according to requested 
scope
+                    dependencyArtifacts = resolveTransitive(systemSession, 
set.getScope(), project);
+                } catch 
(org.eclipse.aether.resolution.DependencyResolutionException e) {
+                    throw new DependencyResolutionException(e.getMessage(), e);
+                }
             } else {
+                // FIXME remove using deprecated method
                 dependencyArtifacts = project.getDependencyArtifacts();
             }
 
             requirements.addArtifacts(dependencyArtifacts);
-            LOGGER.debug("Dependencies for project: " + project.getId() + " 
are:\n"
-                    + StringUtils.join(dependencyArtifacts.iterator(), "\n"));
+            if (LOGGER.isDebugEnabled()) {
+                LOGGER.debug(
+                        "Dependencies for project: {} are:\n{}",
+                        project.getId(),
+                        StringUtils.join(dependencyArtifacts.iterator(), 
"\n"));
+            }
         }
     }
+
+    private Set<Artifact> resolveTransitive(
+            RepositorySystemSession repositorySession, String scope, 
MavenProject project)
+            throws org.eclipse.aether.resolution.DependencyResolutionException 
{
+
+        // scope dependency filter
+        DependencyFilter scoopeDependencyFilter = 
DependencyFilterUtils.classpathFilter(scope);
+
+        // get project dependencies filtered by requested scope
+        List<Dependency> dependencies = project.getDependencies().stream()
+                .map(d -> RepositoryUtils.toDependency(d, 
repositorySession.getArtifactTypeRegistry()))
+                .filter(d -> scoopeDependencyFilter.accept(new 
DefaultDependencyNode(d), null))
+                .collect(Collectors.toList());
+
+        List<Dependency> managedDependencies = 
Optional.ofNullable(project.getDependencyManagement())
+                .map(DependencyManagement::getDependencies)
+                .map(list -> list.stream()
+                        .map(d -> RepositoryUtils.toDependency(d, 
repositorySession.getArtifactTypeRegistry()))
+                        .collect(Collectors.toList()))
+                .orElse(null);
+
+        CollectRequest collectRequest = new CollectRequest();
+        collectRequest.setManagedDependencies(managedDependencies);
+        collectRequest.setRepositories(project.getRemoteProjectRepositories());
+        collectRequest.setDependencies(dependencies);
+        
collectRequest.setRootArtifact(RepositoryUtils.toArtifact(project.getArtifact()));
+
+        DependencyRequest request = new DependencyRequest(collectRequest, 
scoopeDependencyFilter);
+
+        DependencyResult dependencyResult = 
repositorySystem.resolveDependencies(repositorySession, request);
+
+        // cache for artifact mapping
+        Map<org.eclipse.aether.artifact.Artifact, Artifact> 
etherToMavenArtifacts = new HashMap<>();

Review Comment:
   fixed





> Assembly plugin handles scopes wrongly
> --------------------------------------
>
>                 Key: MASSEMBLY-1008
>                 URL: https://issues.apache.org/jira/browse/MASSEMBLY-1008
>             Project: Maven Assembly Plugin
>          Issue Type: Bug
>          Components: dependencySet
>            Reporter: Tamas Cservenak
>            Assignee: Slawomir Jaranowski
>            Priority: Major
>             Fix For: 3.7.0
>
>
> This affects all assembly releases.



--
This message was sent by Atlassian Jira
(v8.20.10#820010)

Reply via email to