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:
- Ask a
MavenProjectfor its artifacts via itsgetArtifacts()call. - Ask the injected
MavenProjectBuilderto build aMavenProjectfor eachArtifact. - Armed with a list of
MavenProjects, callProjectSorterwith that list. - The resulting list of
MavenProjects will be topologically sorted. - Now for each of those
MavenProjects, get its definingArtifactvia itsgetArtifact()method. - Use that
Artifact'sgroupIdandartifactIdto build a colon-separated key. - Use that key to look up the resolved
Artifactin your realMavenProject's artifact map. - 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.
加载中,请稍侯......
精彩评论