如何使用API​​ 3.1.1在Maven插件中使用Aether(eclipse)?

我正在使用API​​ v3.1.1开发一个新的Maven插件,因为我需要升级到Maven 3.1.1,并且需要以Aether的方式处理工件存储库,以及检索工件版本的完整列表。 我正在使用Eclipse Aether(0.9.0.M4),而不是 Sonatype Aether。

我已经通过http://wiki.eclipse.org/Aether阅读并尝试了演示http://git.eclipse.org/c/aether/aether-demo.git/tree/ ,但我还没能理解为什么AbstractMojo的子类中的以下内容不起作用。

RepositorySystem repoSystemRepositorySystemSession repoSessionList projectReposList pluginRepos都为null

我也尝试使用@Component来注入具有相同结果的那些。

有什么我错过了,以便将这些物体注入魔力?

 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, ie 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 projectRepos; /** * The project's remote repositories to use for the resolution of plugins and their dependencies. * * @parameter default-value="${project.remotePluginRepositories}" * @readonly */ private List pluginRepos; // Your other mojo parameters and code here ... } 

最后,它对我有用,我认为它之前不起作用的原因是我的pom.xml中有太多的依赖项而且事情没有得到正确的解决。

这是我用来完成原始post中的代码的完整pom.xml。 其余代码用于aether-demo,其链接也在原帖中提供

  4.0.0 aether.example my-aether-plugin 1.0.1-SNAPSHOT maven-plugin  UTF-8 3.1.1 0.9.0.M4 3.2     org.apache.maven.plugins maven-plugin-plugin ${mavenPluginVersion}  my-aether  true    mojo-descriptor  descriptor    help-goal  helpmojo         org.apache.maven maven-plugin-api ${mavenVersion} provided   org.apache.maven maven-model   org.apache.maven maven-artifact   org.eclipse.sisu org.eclipse.sisu.plexus     org.eclipse.aether aether-api ${aetherVersion}   org.eclipse.aether aether-util ${aetherVersion}   junit junit 4.11 test