Home > Back-end >  Gradle 7: how to get list of implementation dependencies (including sub) in a task?
Gradle 7: how to get list of implementation dependencies (including sub) in a task?

Time:12-16

I need to have full list of dependencies necessary to run a project (so subdependencies are also important!).

task generateLibsDescriptor() {
  doFirst {
    configurations.compileClasspath.resolvedConfiguration.resolvedArtifacts.each {
      println it
    }
  }
}

This code works, but there are also compileOnly dependencies listed. I tried to change compileClasspath to implementation, but had an error Resolving dependency configuration 'implementation' is not allowed as it is defined as 'canBeResolved=false'.

Is it possible to have a list of just implementation dependencies (with subdependencies)?

CodePudding user response:

Configuration compileClasspath extends compileOnly and implementation. New config should be created which extends only implementation but resolvable.

configurations {
        resolvableImpl.extendsFrom(implementation)
        resolvableImpl.canBeResolved(true)
}

task generateLibsDescriptor() {
  doFirst {
    configurations.resolvableImpl.resolvedConfiguration.resolvedArtifacts.each {
      println it
    }
  }
}
  • Related