There are a few ways you can do this. Currently you’re inspecting all of the Depenencies (edges) of the dependency graph. In most cases you want to inspect the Components (nodes) of the graph.
proj.configurations.each { conf ->
ResolutionResult rr = conf.incoming.resolutionResult
// Inspect the components (nodes) of the graph
rr.getAllComponents().each { ResolvedComponentResult cr ->
def isExternal = (cr.id instanceof ModuleComponentIdentifier)
}
// Inspect the dependencies (edges) of the graph
rr.getAllDependencies().each { DependencyResult dr ->
def isExternal = (dr.requested instanceof ModuleComponentSelector)
}
}
Note that ‘DependencyResult.getFrom()’ points to the origin of the dependency, not the component that is the result of resolving that dependency. So your code for getting the selection reason above is not correct.
Actually, the posted code was helpful to describe your problem. I just wanted to point out that using ‘getFrom()’ is probably not going to give you the results you wanted.