Skip to main content

Notice: this Wiki will be going read only early in 2024 and edits will no longer be possible. Please see: https://gitlab.eclipse.org/eclipsefdn/helpdesk/-/wikis/Wiki-shutdown-plan for the plan.

Jump to: navigation, search

Difference between revisions of "Aether/Setting Aether Up"

m
 
(2 intermediate revisions by one other user not shown)
Line 2: Line 2:
  
 
__TOC__
 
__TOC__
 
== Plexus ==
 
 
You can use a Plexus container (or any other dependency injection container that supports Plexus components like [http://www.eclipse.org/sisu/ Sisu]). For instance, assuming you add a dependency on <tt>org.eclipse.sisu:org.eclipse.sisu.plexus:0.0.0.M3</tt> to your POM, the following code fragment discovers the various Aether components from the thread context class loader and wires the system together:
 
<source lang="java">
 
import org.codehaus.plexus.DefaultPlexusContainer;
 
import org.eclipse.aether.RepositorySystem;
 
 
...
 
    private static RepositorySystem newRepositorySystem()
 
        throws Exception
 
    {
 
        return new DefaultPlexusContainer().lookup( RepositorySystem.class );
 
    }
 
...
 
</source>
 
 
We mostly mention this Plexus-based system setup here for completeness. The Plexus container is no longer maintained and users of it should start to migrate to alternatives like JSR-330.
 
  
 
== JSR-330 / Guice / Sisu ==
 
== JSR-330 / Guice / Sisu ==
Line 27: Line 9:
 
[http://code.google.com/p/google-guice/ Google Guice] is a popular implemention of JSR-330. To ease usage of Aether in applications powered by Guice, Aether provides a ready-made Guice module that binds all the stock implementation classes. See our [http://git.eclipse.org/c/aether/aether-demo.git/tree/aether-demo-snippets/src/main/java/org/eclipse/aether/examples/guice/GuiceRepositorySystemFactory.java runnable demo snippets] for a complete example using Guice.
 
[http://code.google.com/p/google-guice/ Google Guice] is a popular implemention of JSR-330. To ease usage of Aether in applications powered by Guice, Aether provides a ready-made Guice module that binds all the stock implementation classes. See our [http://git.eclipse.org/c/aether/aether-demo.git/tree/aether-demo-snippets/src/main/java/org/eclipse/aether/examples/guice/GuiceRepositorySystemFactory.java runnable demo snippets] for a complete example using Guice.
  
For those seeking the simplicity of having components be discovered from the classpath as opposed to manually binding them, [http://www.eclipse.org/sisu/ Sisu] can help. Among others, it extends Guice with automatic/dynamic component discovery. Aether's JARs are equipped with Sisu index files to enable optimal performance during component discovery.
+
For those seeking the simplicity of having components be discovered from the classpath as opposed to manually binding them, [http://www.eclipse.org/sisu/ Sisu] can help. Among others, it extends Guice with automatic/dynamic component discovery. Aether's JARs are equipped with Sisu index files to enable optimal performance during component discovery. Again, our
 +
[http://git.eclipse.org/c/aether/aether-demo.git/tree/aether-demo-snippets/src/main/java/org/eclipse/aether/examples/sisu/SisuRepositorySystemFactory.java demo snippets] provide a working example.
  
 
== Service Locator ==
 
== Service Locator ==
Line 56: Line 39:
  
 
The <tt>DefaultServiceLocator</tt> created via <tt>MavenRepositorySystemUtils</tt> already knows about all the components from <tt>aether-impl</tt> and <tt>maven-aether-provider</tt>, so the remaining missing bits that it needs to be told about are zero or more repository connectors and transporters. Once the locator's internal service registry is populated, the call to <tt>getService()</tt> will create the repository system and recursively initialize its sub components.
 
The <tt>DefaultServiceLocator</tt> created via <tt>MavenRepositorySystemUtils</tt> already knows about all the components from <tt>aether-impl</tt> and <tt>maven-aether-provider</tt>, so the remaining missing bits that it needs to be told about are zero or more repository connectors and transporters. Once the locator's internal service registry is populated, the call to <tt>getService()</tt> will create the repository system and recursively initialize its sub components.
 +
 +
[[Category:Aether]]

Latest revision as of 01:41, 10 July 2014

Aether's implementation consists of a bunch of components that need to be wired together to get a complete repository system. To satisfy different requirements and smoothly integrate into existing applications, Aether offers multiple ways to do so. This page assumes you already know how to set up your classpath with the required libraries, if not, please read Getting Aether first.

JSR-330 / Guice / Sisu

Dependency injection is an established approach to component wiring and got standardized as part of JSR-330. Aether's components are equipped with javax.inject annotations to support usage in JSR-330-enabled applications.

Google Guice is a popular implemention of JSR-330. To ease usage of Aether in applications powered by Guice, Aether provides a ready-made Guice module that binds all the stock implementation classes. See our runnable demo snippets for a complete example using Guice.

For those seeking the simplicity of having components be discovered from the classpath as opposed to manually binding them, Sisu can help. Among others, it extends Guice with automatic/dynamic component discovery. Aether's JARs are equipped with Sisu index files to enable optimal performance during component discovery. Again, our demo snippets provide a working example.

Service Locator

Sometimes, the overhead of using a full-blown dependency injection container is undesirable. To get an instance of the repository system without an IoC container, the classes from the default implementation of Aether provide no-arg constructors and setters to manually wire the components together. But since this isn't really fun to code, the repository system additionally supports wiring via a lightweight service locator pattern.

This service locator infrastructure consists of merely two small interfaces, namely org.eclipse.aether.spi.locator.Service and org.eclipse.aether.spi.locator.ServiceLocator. The components themselves implement the Service interface, and the client of the repository system provides to them an implementation of the ServiceLocator to query other components from.

The module maven-aether-provider from the Apache Maven project provides a simple service locator for Aether that is pre-populated with the components required to deal with Maven repositories. Note that version 3.1.0 or newer of maven-aether-provider is required for usage with Eclipse Aether (earlier versions depend on Sonatype Aether). Usage of said service locator looks like shown below:

import org.apache.maven.repository.internal.MavenRepositorySystemUtils;
import org.eclipse.aether.connector.wagon.WagonProvider;
import org.eclipse.aether.connector.wagon.WagonRepositoryConnectorFactory;
 
...
    private static RepositorySystem newRepositorySystem()
    {
        DefaultServiceLocator locator = MavenRepositorySystemUtils.newServiceLocator();
        locator.addService( RepositoryConnectorFactory.class, BasicRepositoryConnectorFactory.class );
        locator.addService( TransporterFactory.class, FileTransporterFactory.class );
        locator.addService( TransporterFactory.class, HttpTransporterFactory.class );
 
        return locator.getService( RepositorySystem.class );
    }
...

The DefaultServiceLocator created via MavenRepositorySystemUtils already knows about all the components from aether-impl and maven-aether-provider, so the remaining missing bits that it needs to be told about are zero or more repository connectors and transporters. Once the locator's internal service registry is populated, the call to getService() will create the repository system and recursively initialize its sub components.

Back to the top