0

this is what the ideal build script I have:

I do want to execute tasks "unzip_natives_os" manually. But it seems it only works at config phase. And when I take a test run with this set-up it gives me an error: "java.lang.UnsatisfiedLinkError" but if I change the configuration from "nativesOS" into "runtimeOnly" inside of the dependencies block, it works fine. Do I have to explicitly create this "applicationDefaultJvmArgs" and insert the libraryPath of the natives. Is there any other way? And when I need to unzip the "nativesOS" config it needs an explicit version, it seems it did not see the platform/BOM?

// build.gradle.kts
val nativesOS : Configuration by configurations.creating {
    this.isTransitive = false
    this.extendsFrom(configurations.runtimeOnly.get())
}
dependencies {
    implementation(platform("org.lwjgl:lwjgl-bom:3.2.3"))
    listOf(
        "", "-assimp", "-openal",
        "-opengl", "-glfw"
    ).map { lib ->
        implementation("org.lwjgl:lwjgl$lib")

        // I give it an explicit version, because it would not work if I unzip this.
        nativeOS("org.lwjgl","lwjgl$lib", "3.2.3", classifier = LWJGL.lwjglNatives)
    }
    ...
}
// unzip_native_os tasks, here is the problem.
tasks.register<Copy>("unzip_native_os") {
    this.group = "zip"
    doLast {
        nativesOS.asFileTree.filter { it.name.contains("natives") }.forEach {
            unzipTo(File("$buildDir/libs/natives-os"), it)
        }
    }
}

Edited: Why this is not working? I config it first then execute it.

tasks.register<Copy>("unzip_native_os") {
    this.group = "zip"
    val nativesJar = nativesOS.asFileTree.filter { it.name.contains("natives") }.files
    doFirst {
        nativesJar.forEach {
            println(">>>> $it")
            unzipTo(File("$buildDir/libs/natives-os/v2"), it)
        }
    }
}
  • Is there a way to run this tasks name "unzip_native_os" at Execution Phase. – Liveon Phoenix Nov 14 '21 at 08:25
  • Edited: The only possible way to solve this one was to created and to have your own/external community-plugins that have this specific features? On what I've heard "afterEvaluate" method is not safe, specially for a project that needs multiple plugin, it will create an havoc, so what I've heard. – Liveon Phoenix Nov 14 '21 at 09:06
  • You don't need a custom task. As the [linked answer](https://stackoverflow.com/a/31437294/5646962) shows the `doFirst` and `doLast` blocks are executed during the execution phase. – Thomas Kläger Nov 14 '21 at 10:00
  • @Thomas, And as the derived class of DefaultTask with a method annotated of "TaskAction" also run in Execution phase. Rigth? – Liveon Phoenix Nov 14 '21 at 10:31
  • Yes, any Task method annotated with `@TaskAction` will also run in the execution phase. However I doubt that this will help you because the `doLast` action is also executed in the execution phase, so creating a custom task with a "TaskAction" and moving your code there will not significantly change the behavior. – Thomas Kläger Nov 14 '21 at 11:39
  • Our Goal here is to manually execute this Task "unzip_natives_os" or perform its duty at execution phase. Though I do have some problem in parallel to it, but the priority is this _**tasks**_. – Liveon Phoenix Nov 14 '21 at 12:28
  • 1
    Um, Just remove that type in tasks.register and it will work. And again my bad for not realizing this mistake early. – Liveon Phoenix Nov 15 '21 at 12:05

1 Answers1

0

Edited: I found a possible answer and it looks promising but I did not implement it yet, because I need some learning to do on building this kind of script plugin/inline plugin. Here's the link: gradle custom task execution phase

Edited: found an alternative/another quick solution here: Fix custom tasks in gradle. Want to run it manually via at Execution Phase