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
MavenProject
for its artifacts via itsgetArtifacts()
call. - Ask the injected
MavenProjectBuilder
to build aMavenProject
for eachArtifact
. - Armed with a list of
MavenProject
s, callProjectSorter
with that list. - The resulting list of
MavenProject
s will be topologically sorted. - Now for each of those
MavenProject
s, get its definingArtifact
via itsgetArtifact()
method. - Use that
Artifact
'sgroupId
andartifactId
to build a colon-separated key. - Use that key to look up the resolved
Artifact
in 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.
精彩评论