Hey I need help. :smiley: I thought I had done som...
# community-support
j
Hey I need help. 😃 I thought I had done something similar before, but I can't figure out the following and it drives me nuts. I want to extract the
configurations.runtimeClasspath
into a folder structure, where the contents of each Jar file goes into a separate folder. How do I do that?
Copy code
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))
                    }
                }
            }
        })
    }
}
v
I don't think you can do it with a
Copy
or
Sync
task as you cannot dynamically and lazily do the copy spec configuration. So I guess you need something like this (which works):
Copy code
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)
                }
            }
        }
    }
}
j
Thanks. I desperately wanted it to work without my own task/task action. 😄 But I think you are right and it is just not possible.