Unzip files in a specific folder

Hello,

I have a zip file containing a bunch of files at the root. I need to add these files in the output jar in a specific location (let’s say “/folder/inside/jar”). In order to use implicit dependencies between tasks, I tried this:

val unzipFilesTask = tasks.register<Copy>("unzipFiles") {
    from(zipTree(configurations["confForMyZipFile"].singleFile))
    into(layout.buildDirectory.dir("extractedFiles/folder/inside/jar"))
}

sourceSets {
    main {
        resources {
            srcDir(unzipFilesTask )
        }
    }
}

Obviously, in the output jar, the files are at the root since the sourceset uses the folder of the “into” method as an input. I found a way to achieve what I want by using explicit dependencies between tasks, but I would prefer to use implicit dependencies if possible:

val unzipFilesTask = tasks.register<Copy>("unzipFiles") {
    from(zipTree(configurations["confForMyZipFile"].singleFile))
    into(layout.buildDirectory.dir("extractedFiles/folder/inside/jar"))
}

sourceSets {
    main {
        resources {
            srcDir((layout.buildDirectory.dir("extractedFiles"))
        }
    }
}

tasks.named("processResources") {
    dependsOn("unzipFiles")
}
tasks.named("sourcesJar") {
    dependsOn("unzipFiles")
}

Is it possible?