Skip to main content
Jump to: navigation, search

Difference between revisions of "Aether/Creating a Repository System Session"

(Linked to Aether Ant Task code for settings integration)
m
 
(2 intermediate revisions by one other user not shown)
Line 1: Line 1:
{{Warning|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.}}
+
Aether and its components are designed to be stateless and as such all configuration/state has to be passed into the methods. When one makes multiple requests to resolve dependencies, a fair amount of settings usually remains the same across these method calls, like the proxy settings or the path to the local repository. Those settings that tend to be the same for an entire usage session of the repository system are represented by an instance of <tt>org.eclipse.aether.RepositorySystemSession</tt>. Using classes from <tt>maven-aether-provider</tt>, creating such a session that mimics Maven's setup can be done like this:
 
+
 
+
Aether and its components are designed to be stateless and as such all configuration/state has be passed into the methods. When one makes multiple requests to resolve dependencies, a fair amount of settings usually remains the same across these method calls, like the proxy settings or the path to the local repository. Those settings that tend to be the same for an entire usage session of the repository system are represented by an instance of <tt>org.sonatype.aether.RepositorySystemSession</tt>. Using classes from <tt>maven-aether-provider</tt>, creating such a session that mimics Maven's setup can be done like this:
+
  
 
<source lang="java">
 
<source lang="java">
import org.apache.maven.repository.internal.MavenRepositorySystemSession;
+
import org.apache.maven.repository.internal.MavenRepositorySystemUtils;
  
 
...
 
...
 
     private static RepositorySystemSession newSession( RepositorySystem system )
 
     private static RepositorySystemSession newSession( RepositorySystem system )
 
     {
 
     {
         MavenRepositorySystemSession session = new MavenRepositorySystemSession();
+
         DefaultRepositorySystemSession session = MavenRepositorySystemUtils.newSession();
  
 
         LocalRepository localRepo = new LocalRepository( "target/local-repo" );
 
         LocalRepository localRepo = new LocalRepository( "target/local-repo" );
         session.setLocalRepositoryManager( system.newLocalRepositoryManager( localRepo ) );
+
         session.setLocalRepositoryManager( system.newLocalRepositoryManager( session, localRepo ) );
  
 
         return session;
 
         return session;
Line 19: Line 16:
 
</source>
 
</source>
  
As you see, the only setting that must be specified is the local repository, other settings are initialized with default values. Please have a look at the API docs for <tt>MavenRepositorySystemSession</tt> to learn about all the other things you can configure for a session.
+
As you see, the only setting that must be specified is the local repository, other settings are initialized with default values. Please have a look at the API docs for <tt>DefaultRepositorySystemSession</tt> to learn about all the other things you can configure for a session.
 +
 
 +
If you seek a closer cooperation with [http://maven.apache.org/ Apache Maven] and want to read configuration from the user's <tt>settings.xml</tt>, you should have a look at the library <tt>org.apache.maven:maven-settings-builder</tt> which provides the necessary bits. The method <tt>[http://git.eclipse.org/c/aether/aether-ant.git/tree/src/main/java/org/eclipse/aether/internal/ant/AntRepoSys.java#n350 AntRepoSys.getSettings()]</tt> from the Aether Ant Tasks can serve as inspiration for your own code. But please direct any questions regarding usage of that library to the Maven mailing list.
  
If you seek a closer cooperation with [http://maven.apache.org/ Apache Maven] and want to read configuration from the user's <tt>settings.xml</tt>, you should have a look at the library <tt>org.apache.maven:maven-settings-builder</tt> which provides the necessary bits. The method <tt>[http://git.eclipse.org/c/aether/aether-ant.git/tree/src/main/java/org/eclipse/aether/ant/AntRepoSys.java#n305 AntRepoSys.getSettings()]</tt> from the Aether Ant Tasks can serve as inspiration for your own code. But please direct any questions regarding usage of that library to the Maven mailing list.
+
[[Category:Aether]]

Latest revision as of 01:42, 10 July 2014

Aether and its components are designed to be stateless and as such all configuration/state has to be passed into the methods. When one makes multiple requests to resolve dependencies, a fair amount of settings usually remains the same across these method calls, like the proxy settings or the path to the local repository. Those settings that tend to be the same for an entire usage session of the repository system are represented by an instance of org.eclipse.aether.RepositorySystemSession. Using classes from maven-aether-provider, creating such a session that mimics Maven's setup can be done like this:

import org.apache.maven.repository.internal.MavenRepositorySystemUtils;
 
...
    private static RepositorySystemSession newSession( RepositorySystem system )
    {
        DefaultRepositorySystemSession session = MavenRepositorySystemUtils.newSession();
 
        LocalRepository localRepo = new LocalRepository( "target/local-repo" );
        session.setLocalRepositoryManager( system.newLocalRepositoryManager( session, localRepo ) );
 
        return session;
    }

As you see, the only setting that must be specified is the local repository, other settings are initialized with default values. Please have a look at the API docs for DefaultRepositorySystemSession to learn about all the other things you can configure for a session.

If you seek a closer cooperation with Apache Maven and want to read configuration from the user's settings.xml, you should have a look at the library org.apache.maven:maven-settings-builder which provides the necessary bits. The method AntRepoSys.getSettings() from the Aether Ant Tasks can serve as inspiration for your own code. But please direct any questions regarding usage of that library to the Maven mailing list.

Back to the top