1 package org.apache.maven.resolver.examples;
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22 import java.util.List;
23
24 import org.apache.maven.resolver.examples.util.Booter;
25 import org.eclipse.aether.RepositorySystem;
26 import org.eclipse.aether.RepositorySystemSession;
27 import org.eclipse.aether.artifact.Artifact;
28 import org.eclipse.aether.artifact.DefaultArtifact;
29 import org.eclipse.aether.collection.CollectRequest;
30 import org.eclipse.aether.graph.Dependency;
31 import org.eclipse.aether.graph.DependencyFilter;
32 import org.eclipse.aether.resolution.ArtifactResult;
33 import org.eclipse.aether.resolution.DependencyRequest;
34 import org.eclipse.aether.util.artifact.JavaScopes;
35 import org.eclipse.aether.util.filter.DependencyFilterUtils;
36
37
38
39
40 public class ResolveTransitiveDependencies
41 {
42
43 public static void main( String[] args )
44 throws Exception
45 {
46 System.out.println( "------------------------------------------------------------" );
47 System.out.println( ResolveTransitiveDependencies.class.getSimpleName() );
48
49 RepositorySystem system = Booter.newRepositorySystem();
50
51 RepositorySystemSession session = Booter.newRepositorySystemSession( system );
52
53 Artifact artifact = new DefaultArtifact( "org.eclipse.aether:aether-impl:1.0.0.v20140518" );
54
55 DependencyFilter classpathFlter = DependencyFilterUtils.classpathFilter( JavaScopes.COMPILE );
56
57 CollectRequest collectRequest = new CollectRequest();
58 collectRequest.setRoot( new Dependency( artifact, JavaScopes.COMPILE ) );
59 collectRequest.setRepositories( Booter.newRepositories( system, session ) );
60
61 DependencyRequest dependencyRequest = new DependencyRequest( collectRequest, classpathFlter );
62
63 List<ArtifactResult> artifactResults =
64 system.resolveDependencies( session, dependencyRequest ).getArtifactResults();
65
66 for ( ArtifactResult artifactResult : artifactResults )
67 {
68 System.out.println( artifactResult.getArtifact() + " resolved to "
69 + artifactResult.getArtifact().getFile() );
70 }
71 }
72
73 }