30

One can run gradlew dependencies to learn about dependencies of module tasks. It there a way to find transitive dependencies of buildscript dependencies?

Example: classpath 'com.android.tools.build:gradle:1.0.0' depends directly on:

com.android.tools.build builder
com.android.tools.lint lint
net.sf.proguard proguard-gradle
tools.base project-test-lib

As can be seen on MVNRepository. But this artifacts have their own dependencies. Is there and way to find those out without manually traversing whole dependency tree?

As a clarification, the classpath I'm talking about is defined by:

buildscript {
    repositories {}
    dependencies { .... }
}
atok
  • 5,880
  • 3
  • 33
  • 62

3 Answers3

57

Beginning with Gradle 2.10 you can now get information on buildscript dependencies via

gradle buildEnvironment

With older versions you'll have to explicitly define a task of type DependencyReportTask configured with your build script configuration.

task buildscriptDependencies(type: DependencyReportTask) {
    configurations = [buildscript.configurations.classpath]
}
mhsmith
  • 6,675
  • 3
  • 41
  • 58
Mark Vieira
  • 13,198
  • 4
  • 46
  • 39
  • Unfortunately, `gradle buildEnvironment` seems to output nothing for core plugins. For example for `apply plugin: 'application'` to dependencies are shown, although the `application` plugin depends on the `java` plugin. – sschuberth Dec 12 '16 at 20:06
  • @sschuberth if you simply what to know what all plugins are used by a build I'd suggest investigate [build scans](https://scans.gradle.com/s/pqarplj4ogagg/plugins). For example https://scans.gradle.com/s/pqarplj4ogagg/plugins. – Mark Vieira Feb 01 '17 at 03:50
  • With build scans being a public cloud-based service, that would only work if I'm fine with disclosing details about my source code / build system in the open, which sometimes I'm not. I'm aware of the on-premises version with Gradle Enterprise, but I'd really prefer something that works "offline" and creates report on my local disk. – sschuberth Feb 01 '17 at 08:04
1

I think you're looking for Gradle's DependencyInsightReportTask

Mark
  • 590
  • 7
  • 17
  • Can you give an example how to use it to get the report of buildscript dependencies ? – atok Jan 05 '15 at 13:05
  • Just add the task: task allDepInsight(type: DependencyInsightReportTask) << {} Then run gradle allDepInsight – Mark Jan 05 '15 at 13:13
  • It results in the following error: Execution failed for task ':SdkTestApp:allDepInsight'. > Dependency insight report cannot be generated because the input configuration was not specified. It can be specified from the command line, e.g: ':SdkTestApp:allDepInsight --configuration someConf --dependency someDep' – atok Jan 05 '15 at 13:19
  • Hm, it seems you need to specify the dependency: gradle allDepInsight --configuration testRuntime --dependency org.slf4j:slf4j-simple I don't know how to do it for all the dependecies is the project.. – Mark Jan 05 '15 at 13:24
  • I can't seem to find configurations, even though the report and docs say there should be some (Using whatever comes with Android Studio v1.5) – Hunter-Orionnoir Mar 31 '16 at 20:18
-7

You can use this command:

gradle dependencyInsight --dependency gradle

There is awesome tutorial by Udacity, Gradle for Android, but you can watch this video for more explanation.

Hesam
  • 52,260
  • 74
  • 224
  • 365
  • 1
    "Dependency insight report cannot be generated because the input configuration was not specified.", tried adding `--configuration classpath`, but it still gave me the same error. Also tried `compile` and `runtime` to no avail. Any ideas? (Gradle 3.5) – TWiStErRob Dec 11 '17 at 12:30
  • 2
    This answer is not correct. First, as the above comment mentions, the `dependencyInsight` task requires a configuration name to be provided via the `--configuration` option. Second, only project configurations, not the buildscript configurations, are exposed to this task. – Mark Vieira Dec 12 '17 at 03:56