How to retrieve all project dependencies (from non-resolving configurations)


(two) #1

Hello all, I am trying to get Gradle project dependencies and I am struggling with retrieving dependencies from configurations with resolving errors. Basically, I collect dependencies from all configurations by calling ‘resolve’ method on each configuration:

project.configurations.collect { configuration ->
configuration.resolve()
}

Unfortunately this approach does not work when some of the configurations fails to resolve. I found out that I am able to overcome this issue by using:

configuration.getResolvedConfiguration.hasError()

and not to collect dependencies from failing configurations. Although this works, I do not like this solution because configurations may contain many dependencies - by failing to resolve one dependency, all the other dependencies are not being collected, although Gradle is able to resolve them. To overcome this problem, I tried to use:

configuration.getResolvedConfiguration().getLenientConfiguration().getAllModuleDependencies().getFiles()

This kind of works, but the files returned do not correspond to what is being retrieved by calling configuration.resolve(). For example, when I compare the output for project ‘mockito’ (https://github.com/mockito/mockito) using both approaches, the configuration.resolve() method returns one dependency more:

‘mockito\build\classes\test’

This happens even when ‘mockito’ does not have any problems with resolving dependencies.

Can anyone help me here please? Am I missing something?


(Chris Doré) #2

Check out configurations.xyz.incoming.resolutionResult.allDependencies. It returns a set of resolved and unresolved dependencies.

https://docs.gradle.org/current/javadoc/org/gradle/api/artifacts/result/ResolutionResult.html#getAllDependencies()