Search code examples
gradlejardependenciesbuild.gradlegradle-kotlin-dsl

How to collect all dependencies in Gradle 7?


With Gradle 6 I used following snippet to collect all dependencies in my project (using project.configurations.runtime) and copy them to a folder "$buildDir/libs".

tasks.register<Copy>("copyDependenciesToLib") {
    into("$buildDir/libs")
    from(project.configurations.runtime)
    doLast {
        println("copyDependenciesToLib:\n  ${project.configurations.runtime.get().files.joinToString("\n  ") { it.absolutePath }}\n  ->\n  $buildDir/libs")
    }
}

I am currently migrating to Gradle 7, and IntelliJ tells me that runtime cannot be resolved, it seems that it has been removed from configuration? Can you point me in the right direction to reproduce the behavior of the above script in Gradle 7?

Unresolved reference


Solution

  • I just found the answer myself.

    A similar question has been asked here.

    Gradle has removed the runtime configuration in Gradle 7.

    Instead, one can use runtimeClasspath.

    Our copy task now looks the following:

    tasks.register<Copy>("copyDependenciesToLib") {
        into("$buildDir/libs")
        from(project.configurations.runtimeClasspath)
        doLast {
            println("copyDependenciesToLib:\n  ${project.configurations.runtimeClasspath.get().files.joinToString("\n  ") { it.absolutePath }}\n  ->\n  $buildDir/libs")
        }
    }