gnodet commented on code in PR #166: URL: https://github.com/apache/maven-assembly-plugin/pull/166#discussion_r1444247702
########## pom.xml: ########## @@ -108,10 +108,9 @@ under the License. </dependency> <dependency> <groupId>org.eclipse.aether</groupId> - <artifactId>aether-api</artifactId> + <artifactId>aether-util</artifactId> <!-- the same version as in Maven 3.2.5 --> Review Comment: Shouldn't we upgrade to Maven 3.6.5 ? It could be a separate PR though... ########## 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: Typo: `etherToMavenArtifacts` -> `aetherToMavenArtifacts` -- 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: issues-unsubscr...@maven.apache.org For queries about this service, please contact Infrastructure at: us...@infra.apache.org