michel-kraemer/gradle-download-task

Explicit file naming for src property

orchestr7 opened this issue · 1 comments

Hi!

In our project save we have updated a version of your plugin to 5.3.0.

And the following code:

@Suppress("GENERIC_VARIABLE_WRONG_DECLARATION")
val downloadSaveCliTaskProvider: TaskProvider<Download> = tasks.register<Download>("downloadSaveCli") {
    dependsOn(":getSaveCliVersion")
    inputs.file(pathToSaveCliVersion)

    // here is the problem:
    src(KotlinClosure0(function = { "https://github.com/saveourtool/save-cli/releases/download/v0.3.4/save-0.3.4-linuxX64.kexe" }))
    dest("$buildDir/download")


    outputs.dir("$buildDir/download/")
    overwrite(false)
}

stopped downloading our sources.

New variant work fine now with explicitly providing the file name:

    src(KotlinClosure0(function = { "https://github.com/saveourtool/save-cli/releases/download/v0.3.4/save-0.3.4-linuxX64.kexe" }))
        // here is the problem:
    dest("$buildDir/download/myFileNameExplicitly.kexe")

So we are just curious, what has changed? :)

The reason why your task does not work is because outputs is set to $buildDir/download and this directory already exists at the time the task is executed so the download will be skipped. Is there a specific reason why you override outputs in your task? The latest version automatically sets outputs correctly. If there is no reason, just remove outputs.dir("$buildDir/download/"). The task will then work again.

Just a quick tip: You don't have to use a Kotlin closure to set your src property. It's a simple string. Even if you need to use a closure because you're generating the value during task initialization, you don't have to use this complicated syntax. Just use something like this:

src { "https://github.com/saveourtool/save-cli/releases/download/v0.3.4/save-0.3.4-linuxX64.kexe" }