ArtifactResolutionResult: tree instead of set

When running an ArtifactResolutionQuery, the resulting ArtifactResolutionResult only provides sets. To help users deal with arbitrary dependency trees and compilation order issues, is there a way to obtain a tree of the resolved dependencies, rather than a set?

Actually, I have found ResolutionResult.getRoot(). It looks promising.

visitDeps(configurations.compile.incoming.resolutionResult.root)
def visitDeps(ResolvedComponentResult tree) {
    for (child in tree.dependencies) {
        visitDeps(child.selected)
    }
}