Creating a RepositorySystemSession

Resolver (formerly Aether) and its components are stateless. You must pass all configuration and state into the methods. When you make multiple requests to resolve dependencies, many settings remain the same across the method calls. These settings include the proxy settings and the path to the local repository. An instance of org.eclipse.aether.RepositorySystemSession represents the settings that remain the same for the entire usage session of the repository system.

You can create a session with classes from maven-resolver-supplier. The code below creates a session that mimics the Maven setup.

import org.eclipse.aether.supplier.RepositorySystemSupplier;

...
    private static RepositorySystemSession newSession( RepositorySystem system )
    {
        RepositorySystemSession.SessionBuilder sessionBuilder = system.createSessionBuilder();

        LocalRepository localRepo = new LocalRepository( "target/local-repo" );
        sessionBuilder.withLocalRepositories( localRepo );

        return sessionBuilder.build();
    }

Only the local repository must be specified. The other settings have default values.

Read the API documentation for RepositorySystemSession.SessionBuilder to learn about all the settings for a session.

If you use a Maven plugin or run code embedded in Maven, the session is already created for you. You can derive a new session with the copy constructor of DefaultRepositorySystemSession if you must alter the session.

To read configuration from the user's settings.xml in a non-Maven project, use the MIMA library. MIMA provides the necessary parts. Direct any questions about MIMA to the Maven mailing list.