Resolve transitive dependencies

So I am trying to write a gradle plugin which would fetch all dependencies of a module (including all transitive dependencies) and then does some computation based on the resolved dependencies.

I spent the last few hours to search the web and various issues and forums, but was not able to get it properly running.

Currently I use the following inside my task:

for (final Configuration configuration : configurations) {
        configuration.incoming.dependencies.each { final dependency ->

            final String group = dependency.group
            final String name = dependency.name
            final String version = dependency.version
            final String artifact_key = "${dependency.group}:${dependency.name}"

            // ..
        }
    }

But after taking a closer look at the data, it seems it only resolves the direct dependencies of this module, and no transitive dependencies of other modules, or transitive dependencies of included modules.

I also tried

if (configuration.canBeResolved) {
            configuration.incoming.artifacts.each { final art ->
                logger.error(art.variant.displayName)
            }
        }

Which will fail with different exceptions

Could not resolve all artifacts for configuration ‘:app:debugAndroidTestCompileClasspath’.
More than one variant of project :library matches the consumer attributes:
- Configuration ‘:library:debugApiElements’ variant android-aidl:
- Found artifactType ‘android-aidl’ but wasn’t required.

So I checked in the plugin code temporary for development as buildSrc here: https://github.com/mikepenz/AboutLibraries/tree/feature/aboutlibs_next_gen/buildSrc/src/main/groovy/com/mikepenz/aboutlibraries/plugin

I’d really appreciate any help.

Thank you very much!

Perhaps some of the work I did in my monkey patch plugin could help where I analyse the transitive dependencies

Thank you very much for your answer.

I tried some similar code with one of the configurations available but sadly it did also not work

Without being an expert in this field I imagine looking into what the gradle-versions-plugin and the buildSrcVersions projects do might help with your issue.