5

New features in gradle-download-task 3.4.0

 2 years ago
source link: https://michelkraemer.com/gradle-download-task-3.4.0/
Go to the source link to view the article. You can view the picture content, updated content and better typesetting reading experience. If the link is broken, please click the button below to view the snapshot at that time.
neoserver,ios ssh client

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.

gradle-download-task.gif

Grab gradle-down­load-task 3.4.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 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 ETagtrueUse the ETag but dis­play a warn­ing if it is weak“all”Use the ETag and do not dis­play a warn­ing if it is weak“stron­gOnly”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 'https://repo.maven.apache.org/maven2/org/citationstyles/styles/1.0/styles-1.0.jar'
    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 'https://repo.maven.apache.org/maven2/org/citationstyles/styles/1.0/styles-1.0.jar'
    dest buildDir
    tempAndMove true
}

Avoid unnecessary import statement

In pre­vi­ous ver­sions, it was ne­ces­sary to im­port the class de.undercouch.gradle.tasks.download.Download 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 'de.undercouch.download' version '3.4.0'
}

// NOT NECESSARY ANYMORE
// import de.undercouch.gradle.tasks.download.Download

task downloadFile(type: Download) {
    src 'https://repo.maven.apache.org/maven2/org/citationstyles/styles/1.0/styles-1.0.jar'
    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.


About Joyk


Aggregate valuable and interesting links.
Joyk means Joy of geeK