How to take all the dependencies of a particular configuration from all projects in a multi-project build

Team,

I have a configuration like below in root project’s build.gradle

allprojects {
   configurations {
      client
   }
}

And in each project there will be dependencies block like below

dependencies {
    client 'group:artifact:version'
    client 'group:artifact2:version'
    client 'group:artifact3:version'
}

In the copy task of rootProject, I have below lines.

CopySpec clientLibsCopySpec = copySpec {
    into 'release'
    into('client-libs') {from configurations.client}
}

This does not copy any dependency jars to the lib directory.

I m ok to slightly alter the above usage like below

CopySpec clientLibsCopySpec = copySpec {
    into 'release'

    allprojects.each {proj ->
        into('client-libs') {from proj.configurations.client}
    }
}

But, It does not pickup the latest version of the the dependencies across projects if there are some duplicate library entries with different versions…

The objective here is to copy some specific dependencies to client-libs directory.

Hope the issue is clear

Kindly advice how to do it in gradle version 6.1

I m still in searching gradle docs to resolve this requirement?

Pls support

Not sure how pretty this is, but maybe something like this?

// Root project

dependencies {
    subprojects {
        client project(path: it.path, configuration: "client")
    }
}

task copyClientDeps(type: Copy) {
    from configurations.client
    into "$buildDir/release/client-libs"
}

It might be better to model the dependencies as variants though. But in either case, you will need to declare dependencies on your client libraries in order to have the dependency resolution rules take effect.

Another thing you might want to look into is using the same versions of your client dependencies inside each client project. Otherwise you are building and testing against one version, but possibly releasing against another.

That solved my problem.
client project(path: it.path, configuration: "client")

This line of yours made the trick i wanted.

Thanks a lot !