Copy configured/specific dependencies of subprojects into single directory


We have Java multi-project build . In main build.gradle under subproject section added configurations { vendorLibs } & created copy task as given below ; Few subprojects uses this configuration under dependency for 3rd party vendor lib;

task copyLocalArtifacts (type: Copy ) {
from subprojects.collect { it.tasks.withType(Jar) }
into “/opt/destDir”

from subprojects.collect { "${it.buildDir}/resources/main/features" }
into "/opt/destDir/features"

 from subprojects.collect { it.configurations.vendorLibs }
into "/opt/destDir/libs"


This task works for copying jar and feature config files. But not copying 3rd party vendor jar under /opt/destDir/libs; It works only if I move this task under subproject ( up on adding configurations { vendorLIbs }). Any suggestions to fix this issue? The version of gradle is 4.2