How can I get a list of all configurations for a Gradle project?

Gradle

Gradle Problem Overview


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?

Gradle Solutions


Solution 1 - Gradle

Have you tried:

configurations.each { println it.name }

?

Solution 2 - Gradle

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.

Solution 3 - Gradle

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.

Solution 4 - Gradle

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

Solution 5 - Gradle

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.

Solution 6 - Gradle

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


...

Solution 7 - Gradle

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

configurations.forEach { println(it) }

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

Solution 8 - Gradle

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

Attributions

All content for this solution is sourced from the original question on Stackoverflow.

The content on this page is licensed under the Attribution-ShareAlike 4.0 International (CC BY-SA 4.0) license.

Content TypeOriginal AuthorOriginal Content on Stackoverflow
QuestionCliabhachView Question on Stackoverflow
Solution 1 - GradleOpalView Answer on Stackoverflow
Solution 2 - GradleMarkView Answer on Stackoverflow
Solution 3 - GradleNiel de WetView Answer on Stackoverflow
Solution 4 - GradleMike HanafeyView Answer on Stackoverflow
Solution 5 - GradleBlundellView Answer on Stackoverflow
Solution 6 - GradletricknologyView Answer on Stackoverflow
Solution 7 - GradleMahozadView Answer on Stackoverflow
Solution 8 - Gradleuser1942586View Answer on Stackoverflow