Skip to main content

Notice: This Wiki is now read only and edits are no longer 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/Using Aether in Maven Plugins"

(Added maven prereq to POM snippet)
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 Maven has adopted Eclipse Aether.}}
+
[http://maven.apache.org/ Apache Maven] 3.x uses Aether for repository tasks and Maven plugins that target Maven 3.x can do so as well. To start, you likely want to add the following dependencies to your plugin POM:
 
+
 
+
[http://maven.apache.org/ Apache Maven] 3.0.x uses Aether for repository tasks and Maven plugins that target Maven 3.x can do so as well. To start, you likely want to add the following dependencies to your plugin POM:
+
 
<source lang="xml">
 
<source lang="xml">
 
<project>
 
<project>
 
   ...
 
   ...
 
   <prerequisites>
 
   <prerequisites>
     <maven>3.0</maven>
+
    <!-- Maven 3.1.0 is the earliest version using Eclipse Aether, Maven 3.0.x uses the incompatible predecessor Sonatype Aether -->
 +
     <maven>3.1</maven>
 
   </prerequisites>
 
   </prerequisites>
  
Line 13: Line 11:
 
     <dependency>
 
     <dependency>
 
       <!-- required in all cases -->
 
       <!-- required in all cases -->
       <groupId>org.sonatype.aether</groupId>
+
       <groupId>org.eclipse.aether</groupId>
 
       <artifactId>aether-api</artifactId>
 
       <artifactId>aether-api</artifactId>
       <version>1.8</version>
+
       <version>0.9.0.M2</version>
 
     </dependency>
 
     </dependency>
 
     <dependency>
 
     <dependency>
 
       <!-- optional helpers, might be superfluous depending on your use case -->
 
       <!-- optional helpers, might be superfluous depending on your use case -->
       <groupId>org.sonatype.aether</groupId>
+
       <groupId>org.eclipse.aether</groupId>
 
       <artifactId>aether-util</artifactId>
 
       <artifactId>aether-util</artifactId>
       <version>1.8</version>
+
       <version>0.9.0.M2</version>
 
     </dependency>
 
     </dependency>
 +
    <!--
 +
    WARNING: Beware of http://jira.codehaus.org/browse/MNG-5513 which is triggered by a direct or transitive dependency on aether-impl in compile or runtime scope.
 +
    -->
 
     ...
 
     ...
 
   </dependencies>
 
   </dependencies>
Line 32: Line 33:
 
Next, in your mojo source, you would need to grab the repository related components and parameters:
 
Next, in your mojo source, you would need to grab the repository related components and parameters:
 
<source lang="java">
 
<source lang="java">
import org.sonatype.aether.RepositorySystem;
+
import org.eclipse.aether.RepositorySystem;
import org.sonatype.aether.RepositorySystemSession;
+
import org.eclipse.aether.RepositorySystemSession;
import org.sonatype.aether.repository.RemoteRepository;
+
import org.eclipse.aether.repository.RemoteRepository;
 
...
 
...
  
Line 76: Line 77:
 
</source>
 
</source>
 
Usually, you need only <tt>projectRepos</tt> or <tt>pluginRepos</tt> depending on the nature of artifacts your plugin is dealing with, so the other plugin parameter would be superfluous in that case. But in general, the bits shown above should give you all handles that you need to work with Aether from within a Maven plugin.
 
Usually, you need only <tt>projectRepos</tt> or <tt>pluginRepos</tt> depending on the nature of artifacts your plugin is dealing with, so the other plugin parameter would be superfluous in that case. But in general, the bits shown above should give you all handles that you need to work with Aether from within a Maven plugin.
 +
 +
[[Category:Aether]]

Latest revision as of 01:43, 10 July 2014

Apache Maven 3.x uses Aether for repository tasks and Maven plugins that target Maven 3.x can do so as well. To start, you likely want to add the following dependencies to your plugin POM:

<project>
  ...
  <prerequisites>
    <!-- Maven 3.1.0 is the earliest version using Eclipse Aether, Maven 3.0.x uses the incompatible predecessor Sonatype Aether -->
    <maven>3.1</maven>
  </prerequisites>
 
  <dependencies>
    <dependency>
      <!-- required in all cases -->
      <groupId>org.eclipse.aether</groupId>
      <artifactId>aether-api</artifactId>
      <version>0.9.0.M2</version>
    </dependency>
    <dependency>
      <!-- optional helpers, might be superfluous depending on your use case -->
      <groupId>org.eclipse.aether</groupId>
      <artifactId>aether-util</artifactId>
      <version>0.9.0.M2</version>
    </dependency>
    <!--
    WARNING: Beware of http://jira.codehaus.org/browse/MNG-5513 which is triggered by a direct or transitive dependency on aether-impl in compile or runtime scope.
    -->
    ...
  </dependencies>
  ...
</project>

Note: At runtime, the actual version of aether-api being used is enforced by the Maven core, just like other Maven APIs. So be sure to compile/test your plugin against the version of aether-api that is used by the mininum version of Maven that your plugin wants to support.

Next, in your mojo source, you would need to grab the repository related components and parameters:

import org.eclipse.aether.RepositorySystem;
import org.eclipse.aether.RepositorySystemSession;
import org.eclipse.aether.repository.RemoteRepository;
...
 
public MyMojo extends AbstractMojo
{ 
 
    /**
     * The entry point to Aether, i.e. the component doing all the work.
     * 
     * @component
     */
    private RepositorySystem repoSystem;
 
    /**
     * The current repository/network configuration of Maven.
     * 
     * @parameter default-value="${repositorySystemSession}"
     * @readonly
     */
    private RepositorySystemSession repoSession;
 
    /**
     * The project's remote repositories to use for the resolution of project dependencies.
     * 
     * @parameter default-value="${project.remoteProjectRepositories}"
     * @readonly
     */
    private List<RemoteRepository> projectRepos;
 
    /**
     * The project's remote repositories to use for the resolution of plugins and their dependencies.
     * 
     * @parameter default-value="${project.remotePluginRepositories}"
     * @readonly
     */
    private List<RemoteRepository> pluginRepos;
 
    // Your other mojo parameters and code here
    ...
}

Usually, you need only projectRepos or pluginRepos depending on the nature of artifacts your plugin is dealing with, so the other plugin parameter would be superfluous in that case. But in general, the bits shown above should give you all handles that you need to work with Aether from within a Maven plugin.

Back to the top