On Tue, Feb 15, 2011 at 8:22 AM, Ron Wheeler <rwhee...@artifact-software.com > wrote:
> Doesn't your IDE do this already? > No, how could it? Maybe I wasn't clear. I am writing a Maven plugin. For reasons I can go into if anyone cares, I need to process some resolved dependencies in topological order. That is, I will be using this plugin to perform some operations on a Maven project that uses it. The Maven project will, of course, have dependencies. However, if I ask Maven for a list of those dependencies, they will be sorted in "Maven order", not topological order. This is, again, inside a plugin that I'm writing. So I am not running Maven here as an end user; I am interacting with Maven's API. By "Maven order" what I mean is that in a Maven project if project A needs project B, and also declares a dependency on project C, AND if project B declares a dependency on project C, then ALTHOUGH project C is reachable transitively from A (i.e. it doesn't NEED to declare C in its list of dependencies), it will show up ahead of B in the list of artifacts that Maven reports as the dependencies for project A. I need to account for these situations in my plugin. I need to topologically sort that list instead, so that no matter how you have it declared project C in such a case will always come last. In case it matters, my plugin doesn't have anything to do with classpaths (i.e. I'm not re-implementing Maven's dependency resolution algorithm or anything silly like that). I am attempting to process well-known resources in the jar files of other artifacts in topological order. To my knowledge there is no API inside of Maven--the maven-dependency-plugin included--that will take a list of Artifacts and sort them and their transitive dependencies topologically, not according to the classpath-building algorithm that Maven uses when sorting such dependencies for Maven execution. The closest thing I've found is ProjectSorter ( http://maven.apache.org/ref/3.0.2/maven-core/apidocs/org/apache/maven/project/ProjectSorter.html) which topologically sorts a list of *projects*, but I would like to accomplish the same thing with *Artifacts*. Best, Laird