Get Transitive dependencies in Plugin


(Siva Jeganathan) #1

#1. I am trying to fetch transitive dependencies inside a gradle plugin . I tried to use getAllDependencies api for configuration object. But I am still unable to get transitive dependencies. Is there anything I am missing ?

for (Configuration cfg : project.getConfigurations()) {
DefaultDependencySet depset = (DefaultDependencySet) cfg.getAllDependencies();


#2. How does cfg.getIncoming().getDependencies differ from cfg.getAllDependencies or cfg.getDependencies ?

(Stefan Oehme) #2

Configuration.dependencies gives you the declared dependencies, i.e. what the user wrote in their build script. It does not resolve anything.

Configurationincoming.resolutionResult gives you the resolved dependency graph. There is also Configurationincoming.artifacts when you only need a flat list of artifacts and their origin.

Configuration.incoming.dependencies is just an alias for Configuration.allDependencies.

Gradle 4.6 will have much improved documentation on this in the user guide

Please note that resolving dependencies is costly, so doing this in a loop over all projects and all configurations will be a slow process. What’s your use case?

(uklance) #3

You might find the following code helpful where I determine the set of transitive dependencies for a given artifact

(Stefan Oehme) #4

@Lance your example is using the resolvedConfiguration API which we’ll deprecated and remove soon. Please always use Configuration.incoming.

(uklance) #5

Thanks for the code review :blush:

(Siva Jeganathan) #6

@Lance, @st_oehme

Thanks for your reply. I tried your inputs. Please help me how I can distinguish between transitive dependencies and declared/original dependencies from Configuration.incoming.dependencies ?