How to copy dependencies to different sub folders

Hi All,

I have defined some dependencies in my build and i want to copy each dependent jar to a subfolder under lib. May i know how can i perform it in the build script.

I tried the below but its not working.
I want to copy all spring jars to projectBuildDir/lib/springframework and apache commons jars to projectBuildDir/lib/commons

dependencies {

implementation “org.springframework:spring-core:5.1.7.RELEASE”
implementation “org.springframework:spring-beans:5.1.7.RELEASE”
implementation “org.springframework:spring-web:5.1.7.RELEASE”
implementation “commons-io:commons-io:1.4”

}

task copyLibToBuild(type: Copy) {
// from configurations.runtimeClasspath
// from jar
//into “$buildDir/output/lib”

configurations.runtimeClasspath.each {
if(it.name.startsWith(“spring”)) {
// println “it : $it and name is $it.name”
from it
into “$buildDir/output/lib/springframework”
}
else if(it.name.startsWith(“commons”)) {
// println “it : $it and name is $it.name”
from it
into “$buildDir/output/lib/commons”
}
else
{
from it
into “$buildDir/output/lib”
}
}
}

can someone help me on this please.

Try something like the following:

task copyLibToBuild() {
	doLast {
		copy {
			from configurations.runtimeClasspath
			into "$buildDir/output/lib/log4j"
			include "log4j*"
		}
		copy {
			from configurations.runtimeClasspath
			into "$buildDir/output/lib/bc"
			include "bc*"
		}
		copy {
			from configurations.runtimeClasspath
			into "$buildDir/output/lib"
			exclude "bc*"
			exclude "log4j*"
		}
	}
}

Thank you very much Taylor, that worked.