Copy files from dependency jar with kotlin build skript

I’m trying to unzip/copy some files from a single dependency.jar.

This reply shows how to configure a corresponding task in groovy, which has worked for me in the past.

Now trying to achieve the same with a kotlin build script yields a java.lang.IllegalStateException: Expected configuration 'myExtraDepedency' to contain exactly one file, however, it contains more than one file.

When I debug into the script I can see that myExtraDependency.files() contains all depedencies of my project. Perhaps I have a misconception of what myExtraDependency.files() should contain but I expected it to only contain my single somedependency.jar.

val myExtraDependencyby configurations.creating

dependencies {
    myExtraDependency("com.acme:somedependency:1.0.0")
}

val unzipMyExtraDependency by tasks.creating(Copy::class) {
    group = "unzip"
    from(zipTree(myExtraDependency.singleFile))
    include("/interesting_files/**")
    into("$projectDir/build/tmp/")
}

Here is my workaround for now. I would appreciate if you could explain what I’m doing wrong. Thank you very much in advance.

val unzipMyExtraDependency by tasks.creating(Copy::class) {
    group = "unzip"
    val somedependencyJar = myExtraDependency.files().find { it.name.contains("somedependency") }
    from(zipTree(somedependencyJar !!))
    include("/interesting_files/**")
    into("$projectDir/build/tmp/")
}

Re-Reading the quoted answer in groovy I just realized my mistake. The configuration has to be declared as not beeing transitive.

val myExtraDependencyby configurations.creating {
    setTransitive(false) // <-- This was missing
}

dependencies {
    myExtraDependency("com.acme:somedependency:1.0.0")
}

val unzipMyExtraDependency by tasks.creating(Copy::class) {
    group = "unzip"
    from(zipTree(myExtraDependency.singleFile))
    include("/interesting_files/**")
    into("$projectDir/build/tmp/")
}