michel-kraemer / gradle-download-task

📥 Adds a download task to Gradle that displays progress information
Apache License 2.0
679 stars 84 forks source link

Allow a provider for property `checksum` #402

Open jansorg opened 2 months ago

jansorg commented 2 months ago

Is your feature request related to a problem? Please describe.

The workflow is like this

  1. Download a manifest file containing file URL and checksum
  2. Download the file
  3. Verify the file with the manifest's checksum

Describe the solution you'd like

Because checksum is a plain string I need to assign a value when the task is configured. But the manifest's checksum is only available after the download of the manifest file.

Describe alternatives you've considered

Seems to work, but not very nice:

checksum("dummy")
doFirst {
  checksum(checksumFromManifest)
}
michel-kraemer commented 2 months ago

Thanks for reporting this. You are right that lazy configuration is not properly implemented in gradle-download-task yet. As a matter of fact, the properties that do allow it are almost always evaluated during initialization, which is too early for your use case. I could make it so that the checksum property is evaluated later but I'd rather not mix different approaches in one version.

I'll keep this issue open and implement lazy task configuration properly in the next major version of gradle-download-task.

In the meantime, you can use the verifyChecksum extension to achieve the same thing:

task downloadFile(type: Download) {
    src 'http://yourserver.com/file.dat'
    dest layout.buildDirectory
}

task downloadChecksumFile(type: Download) {
    src 'http://yourserver.com/file.dat.md5'
    dest layout.buildDirectory
}

task verifyFile(dependsOn: [downloadChecksumFile, downloadFile]) {
    doLast {
        verifyChecksum.run {
            src downloadFile.outputs.files.singleFile
            algorithm 'MD5'
            checksum downloadChecksumFile.outputs.files.singleFile.text
        }
    }
}

I hope this helps. Let me know if you have questions.