1

Why this is not working?

I config it first then unzip it at the execution phase where I could run it manually.

val nativesOS : Configuration by configurations.creating {
    this.isTransitive = false
    this.extendsFrom(configurations.runtimeOnly.get())
}

dependencies {
    implementation(platform("org.lwjgl:lwjgl-bom:3.2.3"))

    nativeOS("org.lwjgl","lwjgl", "3.2.3", classifier = "natives-windows")
    
    ...
}
// config-phase
tasks.register<Copy>("unzip_native_os") {
    this.group = "zip"

    // config-phase
    val nativesJar = nativesOS.asFileTree.filter { it.name.contains("natives") }.files

    // execution phase
    doFirst {
        nativesJar.forEach {
            println(">>>> $it")
            unzipTo(File("$buildDir/libs/natives-os"), it)
        }
    }
}

1 Answers1

1

I found a fast solution such as this: by using the build-in methods that seems running both at config and execution phase. And I have this link from "slidedeck.io" https://slidedeck.io/paweloczadly/advanced-gradle-training for more reference about this COPY task.

tasks.register<Copy>("unzip_natives_os") {
    nativesOS.filter{jar->jar.name.contains("natives")}.map {jarNative->
        this.from(zipTree(jarNative).filter{file->file.isFile}) {
            this.include("**/*.dll")
        }
        this.into(layout.buildDirectory.dir("libs/natives-os"))
    }
}

Edited: Or you could also do it like this.

tasks.register<Copy>("unzip_natives_os") {
    this.group = "${project.group}:zip"
    this.from(nativesOS.filter{jar->jar.name.contains("natives")}.map{ jarNative->zipTree(jarNative).filter{file->file.isFile} } ) {
        this.include("*.dll")
    }
    this.into(layout.buildDirectory.dir("libs/natives-os"))
}

Edited: I'm over killing this one but I cannot stop. I added this "extension-function"

fun Configuration.extractFile() = this.filter{jar->jar.name.contains("natives") }.map{ jarNative->zipTree(jarNative).filter{file->file.isFile} }

tasks.register<Copy>("unzip_natives_os") {
    ...
    this.from(nativesOS.extractFile())
    ...
}
  • We could also try and modify this one: `this.into( File(sourceSets.main.get().resources.sourceDirectories.singleFile, "path/to/rez") )` The **first parameter** of _File constructor_ is the _parent path_ which is the _*/main/resources_ and if you have a _sub/child path_ the **last param** is available. it's quite clutter but it work. – Liveon Phoenix Nov 16 '21 at 05:38