Reputation: 7330
I have a list of libraries. They use Maven, Ant or Gradle as a builder.
I've created two Map<String, Set<String>>
objects. The first map has libraryName
and Set
of resulting artifacts, the second map has libraryName
and Set
of its first-level dependencies.
Some libraries depend on each other.
So here's my problem: I need to sort all the libraries by their dependencies on each other, from those which doesn't depend on others to the most dependent ones.
Upvotes: 0
Views: 988
Reputation: 35795
Your libraries form a graph of dependencies, where an arc from A to B means "A depends on B". You need to sort the graph so that no library depends on one later in the list. This order is a topological sorting
https://en.wikipedia.org/wiki/Topological_sorting
and can be achieved e.g. by Kahn's algorithm.
Upvotes: 2