4

I have a custom maven plugin. In order to retrieve project's dependencies I use jcabi-aether library. It works fine for getting the project-scope dependencies. But what I need is to resolve plugin-scope dependencies so the call will look like:

<plugin>
    <groupId>com.maven</groupId>
    <artifactId>some-maven-plugin</artifactId>
    <version>1.0.0-SNAPSHOT</version>
    <configuration>
          <some>${some}/path</some>
    </configuration>
    <dependencies>
          <dependency>
               <groupId>joda-time</groupId>
               <artifactId>joda-time</artifactId>
               <version>2.8.1</version>
               <classifier>sources</classifier>
          </dependency>
   </dependencies>
</plugin>
...
<dependency>
  <groupId>com.jcabi</groupId>
  <artifactId>jcabi-aether</artifactId>
  <version>0.10.1</version>
</dependency>

Does anybody has any idea? Thank you

4

1 回答 1

2

要从execute自定义 Mojo 的方法中检索插件范围依赖项,您需要循环构建的元素,如下所示:

Build build = super.getProject().getBuild();
if (null != build) {
    List<Plugin> plugins = build.getPlugins();
    for (Plugin plugin : plugins) {
        List<Dependency> dependencies = plugin.getDependencies();
        // you can then use your custom code here or just collected them for later usage. 
        // An example of what you can get, below
        for (Dependency dependency : dependencies) {
            getLog().info(dependency.getGroupId());
            getLog().info(dependency.getArtifactId());
            getLog().info(dependency.getVersion());
            getLog().info(dependency.getClassifier());
            getLog().info(dependency.getScope());
            // etc.
        }
    }
}

一旦你有了它们,我相信你可以使用 Aether API 来获取传递依赖,就像你已经为项目依赖所做的那样。

于 2015-12-22T10:28:33.187 回答