27

Based on documentation (4.7.6 - Getting the insight into a particular dependency) we can get the insights for a particular configuration specifying the configuration itself. In the example they are using as configuration compile, which is deprecated. I tried to reproduce the same command replacing, in build.gradle, the compile configuration with the implementation configuration (as I got we are not supposed to use compile anymore). But when I run:

gradle dependencyInsight --dependency groovy --configuration implementation

Gradle is returning:

Execution failed for task ':dependencyInsight'.
Resolving configuration 'implementation' directly is not allowed

My build.gradle file is the following:

apply plugin: 'java-library'

repositories {
    jcenter()
}

dependencies{
    implementation 'org.codehaus.groovy:groovy-all:2.4.10'
}

Does it mean I cannot get the insight of a dependency if I'm using implementation or is there another way to get it?

acejazz
  • 789
  • 1
  • 7
  • 27

2 Answers2

21

I had a similar problem, asked around and got this answer:

The configuration is compileClasspath. If you have variants, there is a configuration per-variant (e.g. for the release variant, your configuration would be releaseCompileClasspath).

Examples

  1. No variants: gradle dependencyInsight --dependency groovy --configuration compileClasspath;
  2. Release variant: gradle dependencyInsight --dependency groovy --configuration releaseCompileClasspath

Note

There are a few ways to figure out the available configurations.

  1. If you add configurations.each { println it.name } to your top-level gradle file, the next time you run a task, you'll also get a list of all of your configurations.
  2. Run the dependencies task on your top-level module - this will output all dependencies for all configurations. It can be a lot of text, so you could pipe it into a text file for easier searching (gradle dependencies > dependencies.txt)
Adil Hussain
  • 30,049
  • 21
  • 112
  • 147
Eric Brynsvold
  • 2,880
  • 3
  • 17
  • 22
  • 1
    Can you give me an example, perhaps with the code I posted above? I'm still a beginner with Gradle and Groovy. :) – acejazz Oct 30 '17 at 08:09
  • @acejazz added an example with your input above! – Eric Brynsvold Oct 30 '17 at 20:17
  • 1
    if I execute the command you gave with the build file I provided, it returns: "Configuration with name 'releaseCompileClasspath' not found.". Am I doing something wrong? – acejazz Nov 01 '17 at 07:54
  • Oh, I'm giving you the configuration assuming there is a variant, you should just be able to use `compileClasspath` if there are no variants... let me edit my answer... – Eric Brynsvold Nov 01 '17 at 17:51
  • So, with `compile` configuration (although deprecated) I can use the same configuration name: `--configuration compile`. With `implementation` configuration I must not use the configuration name, but something else `---configuration compileClasspath`. Am I right? – acejazz Nov 03 '17 at 08:03
  • @EricBrynsvold this doesn't seem to work for me :( : `Configuration with name 'compileClasspath' not found.` I'm on Gradle v4.1 (and gradle android plugin v3.0.1). Do you have a link or more info about the configuration 'compileClasspath'? It's not showing up when I print all my configurations like this: `task printConfs { configurations.each { println it.name } }` – kip2 Feb 27 '18 at 17:32
  • 2
    @kip2 I do not know why that configuration does not appear in the list of configurations, but it doesn't on my end either. If your build has variants (if you have build types, like debug/release and/or flavors, then you have variants), then the full configuration name will include the variant. For example, I have a debug/release build type, so the configuration name is `debugCompileClasspath` or `releaseCompileClasspath` – Eric Brynsvold Feb 27 '18 at 22:36
  • You're right, thank you! I parsed out the actual configurations that gradle expects by first running the dependencies check: `./gradlew -q app:dependencies > dependencies.txt`, then noticed from the text file that configurations such as `debugCompileClasspath` were produced – kip2 Feb 28 '18 at 11:31
  • 1
    What is the real answer for this issue? Can someone please post it as an "answer?" – Chris F Apr 07 '21 at 14:56
5

To get the list of available configuration that can be used with dependencyInsight, the easy way is the following :

  1. Open gradle view in android studio View > Tool Windows > Gradle
  2. Select and run task 'Your App' > Tasks > Android > androidDependencies

Then you have a list of all dependencies for all available configuration, just pick one and run :

gradle :mymodule:dependencyInsight --dependency okhttp --configuration flavourDebugCompileClasspath

Hope it helps

Erik B
  • 2,810
  • 1
  • 34
  • 38
avianey
  • 5,545
  • 3
  • 37
  • 60