New features in gradle-download-task 3.4.0

The new ver­sion 3.4.0 of gradle-down­load-task, a Gradle plug­in provid­ing a Download task that dis­play pro­gress in­form­a­tion, has just been re­leased. It con­tains many new fea­tures and up­dat­ing is re­com­men­ded for all users.

Grab gradle-down­load-task 3.4.0 while it’s still hot:

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

New features

Here’s a short over­view of all new fea­tures (more de­tails be­low):

  • Add sup­port for ETags
  • Add tempAndMove con­fig­ur­a­tion flag
  • Re­gister top-level prop­er­ties Download and Verify for the tasks provided by the plug­in
  • Add verifyChecksum ex­ten­sion as an al­tern­at­ive to the Verify task
  • De­prec­ate Java 6
  • De­prec­ate Gradle 1.x
  • Add in­teg­ra­tions tests for all Gradle ver­sions up to 4.6

Support for the HTTP ETag header

The plug­in can now use the HTTP ETag header to check if a file has been changed on the server or not. You can en­able this fea­ture through the onlyIfModified flag and the new useETag flag. If both of them are true, the plug­in will check a file’s timestamp as well as its en­tity tag (ETag) and only down­load it if it has been mod­i­fied on the server since the last down­load. The plug­in can dif­fer­en­ti­ate between strong and weak ETags.

Pos­sible val­ues for the new useETag flag are:

false (de­fault)
Do not use the ETag
Use the ETag but dis­play a warn­ing if it is weak
Use the ETag and do not dis­play a warn­ing if it is weak
Only use the ETag if it is strong

Here’s an ex­ample demon­strat­ing how the new flag can be used:

task downloadFile(type: Download) {
    src ''
    dest buildDir
    overwrite true
    onlyIfNewer true
    useETag true

Download to temporary file and move afterwards

One of the most re­ques­ted fea­tures was the pos­sib­il­ity to down­load a file to a tem­por­ary loc­a­tion and, upon suc­cess­ful ex­e­cu­tion, move it to the fi­nal des­tin­a­tion. This be­ha­vior can now be en­abled with the new tempAndMove flag.

If the overwrite flag is set to false, tempAndMove can be used to avoid par­tially down­loaded files if Gradle is force­fully closed or the sys­tem crashes. Note that the plug­in al­ways de­letes par­tial down­loads on con­nec­tion er­rors, re­gard­less of the value of this flag.

The tem­por­ary loc­a­tion can be con­figured through the new downloadTaskDir con­fig­ur­a­tion prop­erty. The plug­in ap­pends the ex­ten­sion .part to all tem­por­ary files.

The fol­low­ing snip­pet shows how the new flag can be used:

task downloadFile(type: Download) {
    src ''
    dest buildDir
    tempAndMove true

Avoid unnecessary import statement

In pre­vi­ous ver­sions, it was ne­ces­sary to im­port the class to use the Download task. With the new ver­sion 3.4.0 this im­port state­ment is not needed any­more. The same ap­plies to the Verify task.

Of course, the change is back­ward com­pat­ible. You do not have to modify ex­ist­ing build scripts.

plugins {
    id '' version '3.4.0'

// import

task downloadFile(type: Download) {
    src ''
    dest buildDir

More information

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

I also strongly ad­vice to read my blog post on 10 re­cipes for gradle-down­load-task to get an idea what you can do with the plug­in.

Posted by Michel Krämer
on March, 4th 2018.