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

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?


Have you tried:

configurations.each { println it.name }

?


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.


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.


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

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.