[
Date Prev][
Date Next][
Thread Prev][
Thread Next][
Date Index][
Thread Index]
[
List Home]
Re: [aether-users] Sort dependencies topologically
|
Jérémy wrote:
I'm trying to sort the dependencies [...] in a topological way. I tried to
use the PreorderNodeListGenerator from Aether.
Let's start with some minor recap of graph theory. Unless your input DAG
posses additional properties, there can be several topological orderings
[0], so seeing a different output sequence when you change dependency
declaration order in the POM can be expected. A reverse postordering of
a DAG delivers a topological sorting [1]. A reverse postordering is not
the same as a preordering. That said, it's not clear to me why you
picked the PreorderNodeListGenerator for the task.
I have the feeling that PreorderNodeListGenerator sorts a reduced graph,
where the conflicts and so have already been resolved.
The PreorderNodeListGenerator like any other DependencyVisitor visits
the graph that has been provided to it by the caller. In your case, this
is the output of collectDependencies(). Using the default settings
provided by Maven this produces a dependency tree (!) where conflicts
have been resolved. Such a tree does no longer encode all dependency
relationships and cannot be used as input for a topological sort.
To create the graph you need, you need to employ a custom
DependencyGraphTransformer [2] (via a new
DefaultRepositorySystemSession). See NearestVersionConflictResolver as
an example which is the one resolving version conflicts and pruning the
conflicting nodes from the graph.
Benjamin
[0] http://en.wikipedia.org/wiki/Topological_sorting#Uniqueness
[1]
http://en.wikipedia.org/wiki/Depth-first_search#Output_of_a_depth-first_search
[2] https://docs.sonatype.org/display/AETHER/Introduction