use of org.sonatype.aether.resolution.DependencyRequest in project sonatype-aether by sonatype.
the class ResolveTransitiveDependencies method main.
public static void main(String[] args) throws Exception {
System.out.println("------------------------------------------------------------");
System.out.println(ResolveTransitiveDependencies.class.getSimpleName());
RepositorySystem system = Booter.newRepositorySystem();
RepositorySystemSession session = Booter.newRepositorySystemSession(system);
Artifact artifact = new DefaultArtifact("org.sonatype.aether:aether-impl:1.9");
RemoteRepository repo = Booter.newCentralRepository();
DependencyFilter classpathFlter = DependencyFilterUtils.classpathFilter(JavaScopes.COMPILE);
CollectRequest collectRequest = new CollectRequest();
collectRequest.setRoot(new Dependency(artifact, JavaScopes.COMPILE));
collectRequest.addRepository(repo);
DependencyRequest dependencyRequest = new DependencyRequest(collectRequest, classpathFlter);
List<ArtifactResult> artifactResults = system.resolveDependencies(session, dependencyRequest).getArtifactResults();
for (ArtifactResult artifactResult : artifactResults) {
System.out.println(artifactResult.getArtifact() + " resolved to " + artifactResult.getArtifact().getFile());
}
}
use of org.sonatype.aether.resolution.DependencyRequest in project sonatype-aether by sonatype.
the class Aether method resolve.
public AetherResult resolve(String groupId, String artifactId, String version) throws DependencyResolutionException {
RepositorySystemSession session = newSession();
Dependency dependency = new Dependency(new DefaultArtifact(groupId, artifactId, "", "jar", version), "runtime");
RemoteRepository central = new RemoteRepository("central", "default", remoteRepository);
CollectRequest collectRequest = new CollectRequest();
collectRequest.setRoot(dependency);
collectRequest.addRepository(central);
DependencyRequest dependencyRequest = new DependencyRequest();
dependencyRequest.setCollectRequest(collectRequest);
DependencyNode rootNode = repositorySystem.resolveDependencies(session, dependencyRequest).getRoot();
StringBuilder dump = new StringBuilder();
displayTree(rootNode, dump);
PreorderNodeListGenerator nlg = new PreorderNodeListGenerator();
rootNode.accept(nlg);
return new AetherResult(rootNode, nlg.getFiles(), nlg.getClassPath());
}
Aggregations