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

nKognito
  • 6,297
  • 17
  • 77
  • 138
  • I don't see any configuration for jcabi-aether module in your posted maven stuff. – vinay Dec 21 '15 at 15:10
  • @vinay because I use jcabi's backend logics like described in the link I posted. – nKognito Dec 21 '15 at 15:11
  • did you add dependency for jcabi-aether mentioned in the link? – vinay Dec 21 '15 at 15:13
  • Sure.. just updated the question – nKognito Dec 21 '15 at 15:14
  • I think you need to add more code for people to see whats actually wrong. I believe the project-scope dependencies are resolved by maven and not by the library. Your configuration is not able to resolve joda-time? – vinay Dec 21 '15 at 15:24
  • It's not about joda-time. It's about resolving dependencies. I didn't way that something wrong, I need a way to resolve plugin-scope dependencies. – nKognito Dec 21 '15 at 15:59

1 Answers1

2

To retrieve plugin scope dependencies from the execute method of your custom Mojo, you need to loop over the elements of the build as following:

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

Once you have them, I believe you can then use the Aether API to get transitive dependencies as you already did for project dependencies.

A_Di-Matteo
  • 26,902
  • 7
  • 94
  • 128
  • plugin.getDependencies() returns empty list – Daniil Iaitskov Jan 05 '18 at 11:44
  • but is the concerned pom providing them? which version of maven api are you using? – A_Di-Matteo Jan 05 '18 at 12:05
  • I have a custom plugin and I need to retrieve its own dependencies including transitive (which are listed in the pom.xml of the plugin not where it's used). Apache Maven 3.3.9 – Daniil Iaitskov Jan 05 '18 at 12:08
  • then this approach will not work, most probably you need to use the `maven-dependency-plugin` API instead, but it's hard to find an example on its usage, you need to look at maven plugins source code, it's the best (and most probably the only) documentation you can get on this matter. – A_Di-Matteo Jan 05 '18 at 12:23