Friday, 14 May 2021

List all runtime dependencies of a Gradle Android project programmatically

I'm stuck listing transitive closure of runtime dependencies in Gradle Android project. Trying to do it like this:

task listDependencies {
  doLast {
    def configuration = project.configurations.debugRuntimeClasspath
    for (file in configuration.files) {
      println(file)
    }
  }
}

However, this produces following error:

Execution failed for task ':***:listDependencies'.
> Could not resolve all files for configuration ':***:debugRuntimeClasspath'.
   > The consumer was configured to find a runtime of a component, as well as attribute 'com.android.build.api.attributes.BuildTypeAttr' with value 'debug'. However we cannot choose between the following variants of project :***:
       - Configuration ':***:debugRuntimeElements' variant android-aar-metadata declares a runtime of a component, as well as attribute 'com.android.build.api.attributes.BuildTypeAttr' with value 'debug':
           - Unmatched attributes:
               - Provides attribute 'artifactType' with value 'android-aar-metadata' but the consumer didn't ask for it
               - Provides attribute 'com.android.build.api.attributes.VariantAttr' with value 'debug' but the consumer didn't ask for it
       - Configuration ':***:debugRuntimeElements' variant android-assets declares a runtime of a component, as well as attribute 'com.android.build.api.attributes.BuildTypeAttr' with value 'debug':
           - Unmatched attributes:
               - Provides attribute 'artifactType' with value 'android-assets' but the consumer didn't ask for it
               - Provides attribute 'com.android.build.api.attributes.VariantAttr' with value 'debug' but the consumer didn't ask for it
       - Configuration ':***:debugRuntimeElements' variant android-classes-directory declares a runtime of a component, as well as attribute 'com.android.build.api.attributes.BuildTypeAttr' with value 'debug':


from List all runtime dependencies of a Gradle Android project programmatically

No comments:

Post a Comment