You are viewing a plain text version of this content. The canonical link for it is here.
Posted to users@maven.apache.org by Al...@miranda.com on 2013/02/26 22:21:50 UTC

maven graph traversal in plugin


I'm writing a plugin that needs to combine a bunch of artifacts into a zip
and create an XML file of it. I am currently working on creating the XML,
for the rest i use the assembly plugin. To generate the XML i need a way
(an api) to traverse the graph of maven dependencies


Here is a normal hierarchy


the main pom A has B and C as modules. B has a dependency on 1 and 1 has a
dependency on 1.1. Equally, C has a dependency 2 and 2 a dependency 2.1





Now, to get ahold of the two modules B and C i create a member in my mojo,
i am not too happy about this way but i found it in a tutorial
@Parameter( defaultValue = "${reactorProjects}", required = true, readonly
= true )
   private List<MavenProject> reactorProjects;


1) Is this the recommended way to get those (submodules)? i am worried that
this will include not only the two modules under A but also any and all the
other modules higher than A since A is not really the root of the
hierarchy. A itself gets aggregated by other poms


2) Now to get the dependencies of B and of C I do
 for (MavenProject module : reactorProjects) { //for every sub-module
         if (module != project) { //to ignore A
            List<Dependency> dependencies = module.getDependencies();
            for (Dependency dependency : dependencies) { //for every
dependency
               //DO STUFF
            }

         }
 }

With this I can get a reference to 1 and 2 in my example. However, from a
Dependency object i can't further get the dependencies (1.1 and 2.1). What
I would like would be more like getting another MavenProject reference for
each dependency, so that on it I can continue traversing the graph




Can anyone point me on the right direction, any documentation or existing
plugin that i can look into would be appreciated








Thank you,





Alejandro
DISCLAIMER:

Privileged and/or Confidential information may be contained in this
message. If you are not the addressee of this message, you may not
copy, use or deliver this message to anyone. In such event, you
should destroy the message and kindly notify the sender by reply
e-mail. It is understood that opinions or conclusions that do not
relate to the official business of the company are neither given
nor endorsed by the company.

Thank You.