Aether/Resolving Dependencies

From Eclipsepedia

< Aether
Revision as of 20:29, 4 February 2012 by Bentmann.sonatype.com (Talk | contribs)

(diff) ← Older revision | Latest revision (diff) | Newer revision → (diff)
Jump to: navigation, search
Warning2.png
For the time being, this article actually refers to Sonatype Aether, i.e. the predecessor of Eclipse Aether. While the artifact coordinates and class names mentioned below differ slightly from those of Eclipse Aether, the general concept for usage of Aether will remain the same once the Maven Aether Provider has adopted Eclipse Aether.


Extending the code snippets from Setting Aether Up and Creating a Repository System Session, the snippet below demonstrates how to actually resolve the transitive dependencies of say org.apache.maven:maven-profile:2.2.1 and to dump the result as a class path to the console:

    public static void main( String[] args )
        throws Exception
    {
        RepositorySystem repoSystem = newRepositorySystem();
 
        RepositorySystemSession session = newSession( repoSystem );
 
        Dependency dependency =
            new Dependency( new DefaultArtifact( "org.apache.maven:maven-profile:2.2.1" ), "compile" );
        RemoteRepository central = new RemoteRepository( "central", "default", "http://repo1.maven.org/maven2/" );
 
        CollectRequest collectRequest = new CollectRequest();
        collectRequest.setRoot( dependency );
        collectRequest.addRepository( central );
        DependencyNode node = repoSystem.collectDependencies( session, collectRequest ).getRoot();
 
        DependencyRequest dependencyRequest = new DependencyRequest( node, null );
 
        repoSystem.resolveDependencies( session, dependencyRequest  );
 
        PreorderNodeListGenerator nlg = new PreorderNodeListGenerator();
        node.accept( nlg );
        System.out.println( nlg.getClassPath() );
    }

So once you have initialized the repository system and created a session, the general pattern is to create some request object, call its setters to configure the request, do the operation and evaluate the result object.

Since "all theory is grey", we maintain some runnable examples among our sources. These examples provide a more extensive demonstration of Aether and its use, so what are you waiting for?

To learn about how you can control the calculation of transitive dependencies, please see the article about Transitive Dependency Resolution.