Jendrik Johannes
06/16/2026, 12:12 PMconfigurations.runtimeClasspath into a folder structure, where the contents of each Jar file goes into a separate folder. How do I do that?
tasks.register<Copy>("t") {
into("libs") {
from(configurations.runtimeClasspath.map {
it.elements.map {
it.map {
val folderName = it.asFile.nameWithoutExtension
// how can I 'into(folderName)' or 'eachFile { path = "$folderName/path" }' or something like that?
copySpec {
from(zipTree(it))
}
}
}
})
}
}Vampire
06/16/2026, 1:44 PMCopy or Sync task as you cannot dynamically and lazily do the copy spec configuration.
So I guess you need something like this (which works):
interface ArchiveOperationsProvider {
@get:Inject
val archiveOperations: ArchiveOperations
}
interface FileSystemOperationsProvider {
@get:Inject
val fileSystemOperations: FileSystemOperations
}
tasks.register("t") {
val runtimeClasspath: Provider<out FileCollection> = configurations.runtimeClasspath
val archiveOperations = objects.newInstance<ArchiveOperationsProvider>().archiveOperations
val fileSystemOperations = objects.newInstance<FileSystemOperationsProvider>().fileSystemOperations
inputs.files(runtimeClasspath)
outputs.dir("libs")
doLast {
fileSystemOperations.sync {
into("libs")
runtimeClasspath.get().forEach {
val folderName = it.nameWithoutExtension
from(archiveOperations.zipTree(it)) {
into(folderName)
}
}
}
}
}Jendrik Johannes
06/17/2026, 5:07 AM