开发者

Sorting (topological) maven dependencies

We have a number of SNAPSHOT artifacts that we need to release more or less all at once. We were looking for a plug-in that would do the sort and then list 开发者_运维技巧the dependencies (dependency:list seems to give them in alphabetical order, dependency:tree is not particularly convenient for our purposes).

We want to do the sort so that we can release the "least-dependent" artifacts first, followed by those that are "more-dependent".

Has anyone else ever encountered this need?


I just had to do this in a plugin myself. The folks on the Maven list appeared to have no idea that this would be useful. Here's how I did it: http://maven.40175.n5.nabble.com/Topologically-sorting-dependencies-tp3384898p3387803.html

Briefly, in a plugin with dependency resolution set to test:

  1. Ask a MavenProject for its artifacts via its getArtifacts() call.
  2. Ask the injected MavenProjectBuilder to build a MavenProject for each Artifact.
  3. Armed with a list of MavenProjects, call ProjectSorter with that list.
  4. The resulting list of MavenProjects will be topologically sorted.
  5. Now for each of those MavenProjects, get its defining Artifact via its getArtifact() method.
  6. Use that Artifact's groupId and artifactId to build a colon-separated key.
  7. Use that key to look up the resolved Artifact in your real MavenProject's artifact map.
  8. That artifact will now have its getFile() property populated and you can do what you need to with it.

This is unbelievably cumbersome but I don't see any other way of doing it. I hope this helps you out.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜