use of org.apache.maven.project.DefaultDependencyResolutionRequest in project meecrowave by apache.
the class MeecrowaveBundleMojo method addTransitiveDependencies.
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);
}
}
use of org.apache.maven.project.DefaultDependencyResolutionRequest in project bnd by bndtools.
the class DependencyResolver method resolve.
public Map<File, ArtifactResult> resolve() throws MojoExecutionException {
if (resolvedDependencies != null) {
return resolvedDependencies;
}
DependencyResolutionRequest request = new DefaultDependencyResolutionRequest(project, session);
request.setResolutionFilter(new DependencyFilter() {
@Override
public boolean accept(DependencyNode node, List<DependencyNode> parents) {
if (node.getDependency() != null) {
return scopes.contains(node.getDependency().getScope());
}
return false;
}
});
DependencyResolutionResult result;
try {
result = resolver.resolve(request);
} catch (DependencyResolutionException e) {
throw new MojoExecutionException(e.getMessage(), e);
}
Map<File, ArtifactResult> dependencies = new HashMap<>();
DependencyNode dependencyGraph = result.getDependencyGraph();
if (dependencyGraph != null && !dependencyGraph.getChildren().isEmpty()) {
List<RemoteRepository> remoteRepositories = new ArrayList<>(project.getRemoteProjectRepositories());
ArtifactRepository deployRepo = project.getDistributionManagementArtifactRepository();
if (deployRepo != null) {
remoteRepositories.add(RepositoryUtils.toRepo(deployRepo));
}
discoverArtifacts(dependencies, dependencyGraph.getChildren(), project.getArtifact().getId(), remoteRepositories);
}
return resolvedDependencies = dependencies;
}
Aggregations