2014-02-06 127 views
3

我正在開發一個使用API​​ v3.1.1的新Maven插件,因爲我需要升級到Maven 3.1.1,並需要處理工件存儲庫的以太網方式,以及檢索工件版本的完整列表。我使用Eclipse Aether(0.9.0.M4),不是 Sonatype Aether。如何在使用API​​ 3.1.1的Maven插件中使用Aether(eclipse)?

我已經通過閱讀http://wiki.eclipse.org/Aether並試圖演示http://git.eclipse.org/c/aether/aether-demo.git/tree/,但我一直無法理解爲什麼內的AbstractMojo一個子類不起作用以下

兩個RepositorySystem repoSystemRepositorySystemSession repoSessionList<RemoteRepository> projectReposList<RemoteRepository> pluginReposnull

我也嘗試使用@Component注入那些結果相同。

有沒有什麼我錯過了爲了讓這些對象注入mojo?

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 
    ... 
} 
+0

你可以顯示你的插件的完整pom文件嗎? – khmarbaise

+0

是的,問題出現在pom.xml中。我有太多的依賴關係,事情沒有得到妥善解決。現在開始工作,請參閱解決方案udner – Moni

回答

2

最後,它的工作對我來說,我認爲它沒有先前的工作的原因是,我在我的pom.xml有太多的依賴,事情沒有得到正確解析。

這裏是我使用的完整pom.xml,以使原始文章中的代碼正常工作。其餘代碼從以太網​​演示中使用,其鏈接也在原始帖子中提供

<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" 
    xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd"> 
    <modelVersion>4.0.0</modelVersion> 

    <groupId>aether.example</groupId> 
    <artifactId>my-aether-plugin</artifactId> 
    <version>1.0.1-SNAPSHOT</version> 
    <packaging>maven-plugin</packaging> 

    <properties> 
     <project.build.sourceEncoding>UTF-8</project.build.sourceEncoding> 
     <mavenVersion>3.1.1</mavenVersion> 
     <aetherVersion>0.9.0.M4</aetherVersion> 
     <mavenPluginVersion>3.2</mavenPluginVersion> 
    </properties> 

    <build> 
     <plugins> 
      <plugin> 
       <groupId>org.apache.maven.plugins</groupId> 
       <artifactId>maven-plugin-plugin</artifactId> 
       <version>${mavenPluginVersion}</version> 
       <configuration> 
        <goalPrefix>my-aether</goalPrefix> 
        <!-- see http://jira.codehaus.org/browse/MNG-5346 --> 
        <skipErrorNoDescriptorsFound>true</skipErrorNoDescriptorsFound> 
       </configuration> 
       <executions> 
        <execution> 
         <id>mojo-descriptor</id> 
         <goals> 
          <goal>descriptor</goal> 
         </goals> 
        </execution> 
        <execution> 
         <id>help-goal</id> 
         <goals> 
          <goal>helpmojo</goal> 
         </goals> 
        </execution> 
       </executions> 
      </plugin> 

     </plugins> 
    </build> 

    <dependencies> 
     <dependency> 
      <groupId>org.apache.maven</groupId> 
      <artifactId>maven-plugin-api</artifactId> 
      <version>${mavenVersion}</version> 
      <scope>provided</scope> 
      <exclusions> 
       <exclusion> 
        <groupId>org.apache.maven</groupId> 
        <artifactId>maven-model</artifactId> 
       </exclusion> 
       <exclusion> 
        <groupId>org.apache.maven</groupId> 
        <artifactId>maven-artifact</artifactId> 
       </exclusion> 
       <exclusion> 
        <groupId>org.eclipse.sisu</groupId> 
        <artifactId>org.eclipse.sisu.plexus</artifactId> 
       </exclusion> 
      </exclusions> 
     </dependency> 
     <dependency> 
      <groupId>org.eclipse.aether</groupId> 
      <artifactId>aether-api</artifactId> 
      <version>${aetherVersion}</version> 
     </dependency> 
     <dependency> 
      <groupId>org.eclipse.aether</groupId> 
      <artifactId>aether-util</artifactId> 
      <version>${aetherVersion}</version> 
     </dependency> 

     <dependency> 
      <groupId>junit</groupId> 
      <artifactId>junit</artifactId> 
      <version>4.11</version> 
      <scope>test</scope> 
     </dependency> 
    </dependencies> 
</project>