gradle-download-task 2.0.0

The new ver­sion of the Gradle plug­in gradle-down­load-task 2.0.0 has just been re­leased. The plug­in provides a Download task that dis­plays pro­gress in­form­a­tion while down­load­ing files, just like Gradle does when it fetches an ar­ti­fact from a re­pos­it­ory.

Grab gradle-down­load-task 2.0.0 while it’s still hot:
https://github.com/michel-kraemer/gradle-download-task

The new ver­sion has been tested with Gradle 1.x up to 2.6 but should be com­pat­ible to any other ver­sion as well.

New features

Sematic versioning

The plug­in fol­lows the rules of se­mantic ver­sion­ing from now on. This means that any new ma­jor ver­sion in­tro­duces (pos­sible) API in­com­pat­ible changes. Every minor ver­sion adds func­tion­al­ity and every patch ver­sion fixes bugs. See the homepage of se­mantic ver­sion­ing for more de­tails.

Lazy source and destination properties

The src and dest prop­er­ties of the Download task are lazily eval­u­ated now. This means you can provide clos­ures that will only be eval­u­ated when the task is ex­ecuted:

task downloadFile(type: Download) {
    src { "${baseUrl}/${version}" }
    dest { "${baseDest}/${version}" }
}

Ignore invalid or self-signed certificates

The Download task sup­ports a new prop­erty that can be set to ig­nore in­valid (or self-signed) cer­ti­fic­ates.

ac­cept­A­nyCer­ti­fic­ate
true if HT­TPS cer­ti­fic­ate veri­fic­a­tion er­rors should be ig­nored and any cer­ti­fic­ate (even an in­valid one) should be ac­cep­ted. (de­fault: false)

Destination relative to project

The dest prop­erty of the Download task is now re­l­at­ive to the pro­ject dir­ect­ory. This is a pos­sible break­ing change so I de­cided to in­crease the ma­jor ver­sion num­ber. (Pre­vi­ously the prop­erty was re­l­at­ive to the cur­rent work­ing dir­ect­ory.)

New Verify task

The plug­in provides a new Verify task that can be used to check the in­teg­rity of a down­loaded file by cal­cu­lat­ing its check­sum and com­par­ing it to a pre-defined value. The task suc­ceeds if the file’s check­sum equals the given value and fails if it does­n’t.

Use the task as fol­lows:

import de.undercouch.gradle.tasks.download.Verify

task verifyFile(type: Verify) {
    src new File(buildDir, 'file.ext')
    algorithm 'MD5'
    checksum 'ce114e4501d2f4e2dcea3e17b546f339'
}

You can com­bine the down­load task and the verify task as fol­lows:

import de.undercouch.gradle.tasks.download.Download
import de.undercouch.gradle.tasks.download.Verify

task downloadFile(type: Download) {
    src 'http://www.example.com/index.html'
    dest buildDir
}

task verifyFile(type: Verify, dependsOn: downloadFile) {
    src new File(buildDir, 'index.html')
    algorithm 'MD5'
    checksum '09b9c392dc1f6e914cea287cb6be34b0'
}

The verify task sup­ports the fol­low­ing prop­er­ties:

src
The file to verify (re­quired)
check­sum
The ac­tual check­sum to verify against (re­quired)
al­gorithm
The al­gorithm to use to com­pute the check­sum. See the list of al­gorithm names for more in­form­a­tion. (de­fault: MD5)

More information

If you want to learn more about the plug­in have a look at its README file or at my pre­vi­ous post.


Posted by Michel Krämer
on August, 19th 2015.