if ( resolutionResult.getDependencyGraph() != null ) RepositoryUtils.toArtifacts( artifacts, resolutionResult.getDependencyGraph().getChildren(), Collections.singletonList( project.getArtifact().getId() ), null );
if ( result.getDependencyGraph() != null && !result.getDependencyGraph().getChildren().isEmpty() ) RepositoryUtils.toArtifacts( artifacts, result.getDependencyGraph().getChildren(), Collections.singletonList( project.getArtifact().getId() ), collectionFilter );
public static List<Artifact> getAllLibraries(MavenProject project, RepositorySystemSession repositorySystemSession, ProjectDependenciesResolver projectDependenciesResolver) throws MojoExecutionException { DefaultDependencyResolutionRequest dependencyResolutionRequest = new DefaultDependencyResolutionRequest(project, repositorySystemSession); DependencyResolutionResult dependencyResolutionResult; try { dependencyResolutionResult = projectDependenciesResolver.resolve(dependencyResolutionRequest); } catch (DependencyResolutionException ex) { throw new MojoExecutionException(ex.getMessage(), ex); } List<Artifact> artifacts = new LinkedList<Artifact>(); if (dependencyResolutionResult.getDependencyGraph() != null && !dependencyResolutionResult.getDependencyGraph().getChildren().isEmpty()) { RepositoryUtils.toArtifacts(artifacts, dependencyResolutionResult.getDependencyGraph().getChildren(), Collections.singletonList(project.getArtifact().getId()), null); } return artifacts; }
/** * Builds the dependency graph for Maven 3, eventually hacking for collecting projects from * reactor not yet built. * * @param buildingRequest the buildingRequest * @param filter artifact filter (can be <code>null</code>) * @param reactorProjects Collection of those projects contained in the reactor (can be <code>null</code>). * @return DependencyNode containing the dependency graph. * @throws DependencyGraphBuilderException if some of the dependencies could not be resolved. */ @Override public DependencyNode buildDependencyGraph( ProjectBuildingRequest buildingRequest, ArtifactFilter filter, Collection<MavenProject> reactorProjects ) throws DependencyGraphBuilderException { MavenProject project = buildingRequest.getProject(); DependencyResolutionRequest request = new DefaultDependencyResolutionRequest( project, buildingRequest.getRepositorySession() ); DependencyResolutionResult result = resolveDependencies( request, reactorProjects ); return buildDependencyNode( null, result.getDependencyGraph(), project.getArtifact(), filter ); }
/** * Builds the dependency graph for Maven 3, eventually hacking for collecting projects from * reactor not yet built. * * @param project the project * @param filter artifact filter (can be <code>null</code>) * @param reactorProjects Collection of those projects contained in the reactor (can be <code>null</code>). * @return DependencyNode containing the dependency graph. * @throws DependencyGraphBuilderException if some of the dependencies could not be resolved. */ public DependencyNode buildDependencyGraph( MavenProject project, ArtifactFilter filter, Collection<MavenProject> reactorProjects ) throws DependencyGraphBuilderException { ProjectBuildingRequest projectBuildingRequest = (ProjectBuildingRequest) Invoker.invoke( project, "getProjectBuildingRequest" ); DependencyResolutionRequest request = new DefaultDependencyResolutionRequest( project, projectBuildingRequest.getRepositorySession() ); DependencyResolutionResult result = resolveDependencies( request, reactorProjects ); return buildDependencyNode( null, result.getDependencyGraph(), project.getArtifact(), filter ); }
private void addTransitiveDependencies(final File distroFolder, final Collection<String> includedArtifacts, final Dependency dependency) { final DependencyResolutionRequest request = new DefaultDependencyResolutionRequest(); request.setMavenProject(new MavenProject() {{ getDependencies().add(dependency); }}); request.setRepositorySession(session); try { dependenciesResolver.resolve(request).getDependencyGraph().accept(new DependencyVisitor() { @Override public boolean visitEnter(final DependencyNode node) { return true; } @Override public boolean visitLeave(final DependencyNode node) { final org.eclipse.aether.artifact.Artifact artifact = node.getArtifact(); if (artifact != null && !includedArtifacts.contains(artifact.getArtifactId())) { addLib(distroFolder, artifact.getFile()); } return true; } }); } catch (final DependencyResolutionException e) { throw new IllegalStateException(e.getMessage(), e); } }
public void buildDependencyGraph(MavenProject project, ArtifactFilter globalFilter, GraphBuilder<DependencyNode> graphBuilder) { DefaultDependencyResolutionRequest request = new DefaultDependencyResolutionRequest(); request.setMavenProject(project); request.setRepositorySession(getVerboseRepositorySession(project)); DependencyResolutionResult result; try { result = this.dependenciesResolver.resolve(request); } catch (DependencyResolutionException e) { throw new DependencyGraphException(e); } org.eclipse.aether.graph.DependencyNode root = result.getDependencyGraph(); ArtifactFilter transitiveDependencyFilter = createTransitiveDependencyFilter(project); GraphBuildingVisitor visitor = new GraphBuildingVisitor(graphBuilder, globalFilter, transitiveDependencyFilter, this.targetFilter, this.includedResolutions); root.accept(visitor); }