80

I'm trying to get a list of all valid values for the --configuration flag of the dependencyInsight or dependencies gradle tasks. How would I go about doing this with Gradle 3.2.1?

10 Answers 10

60

Have you tried:

configurations.each { println it.name }

?

6
  • 1
    would this go in my main build.gradle file?
    – Cliabhach
    Dec 15, 2016 at 21:31
  • @Cliabhach, yes for instance. You can also add it as a task.
    – Opal
    Dec 15, 2016 at 21:33
  • 8
    No wait, I got it. Turned out I needed to run gradle app:dependencyInsight --dependency joda-time --configuration compile, not gradle dependencyInsight --dependency joda-time --configuration compile.
    – Cliabhach
    Dec 15, 2016 at 21:45
  • 47
    Can this command be run from the command line? I really don't need to put litter into my build scripts.
    – will
    Mar 3, 2017 at 1:46
  • 2
    See Niel's more modern answer stackoverflow.com/a/57530371 that uses ./gradlew projects --info to list configurations Sep 20, 2019 at 16:21
49

Try

gradle --console plain dependencies | fgrep ' - '

The dependencies task lists all configurations (along with their dependencies), and the fgrep will just show you the configuration names (along with a brief description of each). It's not great, but doesn't require you to put stuff in your build script.

3
  • Ooh, interesting idea. What version of Gradle did you use?
    – Cliabhach
    Sep 3, 2018 at 21:15
  • @Cliabhach I don't remember what version I originally did this with, but I'm currently using 4.9 and it still works. BTW, "--console plain" might improve the output (updating my answer to include that).
    – Mark
    Sep 4, 2018 at 12:59
  • This only prints a small subest of configurations. e.g. archives - Configuration for archive artifacts. default - Configuration for default artifacts. jacocoAgent - The Jacoco agent to use to get coverage data. jacocoAnt - The Jacoco ant tasks to use to get execute Gradle tasks. (*) - dependencies omitted (listed previously)
    – Decoded
    Sep 25, 2018 at 14:59
18

With Gradle 5 it's very simple with the --info option. For example:

./gradlew projects --info

Now look in the Configure project section which lists all the configurations.

11
  • Huh, that seems to work well enough on Gradle 5.5.1. I take it you could use --info on any command that configures the project in question, and search for Creating configuration in the output.
    – Cliabhach
    Nov 25, 2019 at 20:24
  • Would you be ok adding a link to official (e.g. gradle.org) documentation on the ./gradlew projects task?
    – Cliabhach
    Nov 25, 2019 at 20:24
  • 1
    @Cliabhach --info simply sets the logging level to INFO Nov 26, 2019 at 15:34
  • 1
    I'll see if I can! The fact that it's called 'projects' doesn't help much...
    – Cliabhach
    Nov 27, 2019 at 17:30
  • 14
    I don't believe this provides useful output any more, probably as a result of Gradle getting smarter about resolvable vs consumable configurations (and not eagerly evaluating all configurations all the time).
    – stkent
    Aug 17, 2021 at 20:50
13

Add this to root project:

allprojects {
    repositories {
        // ....
    }

    task printConfigurations {
        doLast {task ->
            println "Project Name: $project.name configurations:"
            configurations.each {
                println "    $it.name"
            }
        }
    }
}

Then, for example:

$ ./gradlew -q :SubProjA:printConfigurations
Project Name: SubProjA configurations:
    -api
    -runtime
    annotationProcessor
    api
    apiDependenciesMetadata
    apiElements
    archives
    compile
    compileClasspath
    compileOnly
    compileOnlyDependenciesMetadata
    default
    implementation
    implementationDependenciesMetadata
    kotlinCompilerClasspath
    kotlinCompilerPluginClasspath
    kotlinKlibCommonizerClasspath
    kotlinNativeCompilerPluginClasspath
    kotlinScriptDef
    kotlinScriptDefExtensions
    runtime
    runtimeClasspath
    runtimeElements
    runtimeOnly
    runtimeOnlyDependenciesMetadata
    sourceArtifacts
    testAnnotationProcessor
    testApi
    testApiDependenciesMetadata
    testCompile
    testCompileClasspath
    testCompileOnly
    testCompileOnlyDependenciesMetadata
    testImplementation
    testImplementationDependenciesMetadata
    testKotlinScriptDef
    testKotlinScriptDefExtensions
    testRuntime
    testRuntimeClasspath
    testRuntimeOnly
    testRuntimeOnlyDependenciesMetadata
1
  • And is there any way to get for instance all of the "implementation" names? for instance if on my project I have implementation { dagger } could I get this "dagger" name? Oct 26, 2022 at 9:26
4

This is the Kotlin DSL (build.gradle.kts) equivalent of other answers:

configurations.forEach(::println)

Put the above statement at the top of your build.gradle.kts file. It will print something like below whenever you run any task (like build):

configuration ':app:androidApis'
configuration ':app:androidJdkImage'
configuration ':app:androidTestAnnotationProcessor'
...

You can also create a dedicated task for this:

tasks.register("myConfigs") {
    doLast {
        configurations.forEach { println(it) }
    }
}

Run the task from the command line like this:

./gradlew myConfigs
2

Here are all the configurations for the Java plugin:

https://docs.gradle.org/current/userguide/java_plugin.html#sec:java_plugin_and_dependency_management

compile(Deprecated) Compile time dependencies. Superseded by implementation.

implementation extends compile Implementation only dependencies.

compileOnly Compile time only dependencies, not used at runtime.

compileClasspath extends compile, compileOnly, implementation Compile classpath, used when compiling source. Used by task compileJava.

annotationProcessor Annotation processors used during compilation.

runtime(Deprecated) extends compile Runtime dependencies. Superseded by runtimeOnly.

runtimeOnly Runtime only dependencies.

runtimeClasspath extends runtimeOnly, runtime, implementation Runtime classpath contains elements of the implementation, as well as runtime only elements.

testCompile(Deprecated) extends compile Additional dependencies for compiling tests. Superseded by testImplementation.

testImplementation extends testCompile, implementation Implementation only dependencies for tests.

testCompileOnly Additional dependencies only for compiling tests, not used at runtime.

testCompileClasspath extends testCompile, testCompileOnly, testImplementation Test compile classpath, used when compiling test sources. Used by task compileTestJava.

testRuntime(Deprecated) extends runtime, testCompile Additional dependencies for running tests only. Superseded by testRuntimeOnly.

testRuntimeOnly extends runtimeOnly Runtime only dependencies for running tests.

testRuntimeClasspath extends testRuntimeOnly, testRuntime, testImplementation Runtime classpath for running tests. Used by task test.

archives Artifacts (e.g. jars) produced by this project. Used by task uploadArchives.

default extends runtimeClasspath The default configuration used by a project dependency on this project. Contains the artifacts and dependencies required by this project at runtime.

2

If anyone is looking to do this on the command line:

gradle outgoingVariants

You'll have to do some parsing but you'll see something like:

--------------------------------------------------
Variant yummyDebugRuntimeElements
--------------------------------------------------
Description = Runtime elements for debug
Capabilities
    - group:artifact:0.1 (default capability)
Attributes
    - com.android.build.api.attributes.BuildTypeAttr               = debug
    - com.android.build.api.attributes.ProductFlavor:default.      = yummy
    - com.android.build.api.attributes.VariantAttr                 = debug
    - com.android.build.gradle.internal.dependency.AndroidTypeAttr = Aar
    - org.gradle.usage                                             = java-runtime
    - org.jetbrains.kotlin.platform.type                           = androidJvm


...
2
  • That's pretty neat. It can only show *Elements variants though, right?
    – Cliabhach
    Jun 23, 2022 at 6:05
  • I don't exactly recall, that project had a lot of variants and I just grabbed one. This happened to be just one of the places the variant was visible. Oct 3, 2022 at 11:53
1

TL;DR

gradle proj:resolvableConfigurations | grep "^Configuration"

And you probably want the runtimeClasspath configuration for :dependencyInsight.

Explanation:

There's actually a built-in task resolvableConfigurations (since Gradle 7.5), so there's no need for having custom configuration-printing logic in your build scripts any more.

It's output is rather verbose and is kind of unwieldy as means of just figuring out the list of your configurations -- the grep extracts the name lines. Of course, you can go further and cut the word "Configuration" to get just the names:

gradle proj:resolvableConfigurations | grep "^Configuration" | sed "s/Configuration //g"
0

A variation of @Mike Hanafey's answer using Gradle Kotlin DSL, and adding another task that prints only resolvable configurations (useful for passing to the --configuration parameter of dependencyInsight).

allprojects {
  fun printConfigurations(filter: (Configuration) -> Boolean = { true }) {
    configurations.filter(filter).forEach {
      println("\t${it.name}")
    }
  }

  task("printConfigurations") {
    doLast {
      println("${project.name} configurations:")
      printConfigurations()
    }
  }
  task("printResolvableConfigurations") {
    doLast {
      println("${project.name} resolvable configurations:")
      printConfigurations { it.isCanBeResolved }
    }
  }
}
-4

Just run these commands without the --configuration flag and the first lines of the output will be the list of available configurations

2
  • 3
    Can you give an example of what you're talking about? I don't see a list of configurations in the output. May 23, 2019 at 16:54
  • @DavidKennedy I'm unable to reproduce it with my current Gradle 4.10.2 but I recall that in the previous version I had if I had omitted the --configuration flag it would have listed all possible configurations May 27, 2019 at 6:08

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.