1

gradle-download-task: download files with progress

 2 years ago
source link: https://michelkraemer.com/gradle-download-task-download-files-with-progress/
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

gradle-download-task: download files with progress

I really like how Gradle dis­plays pro­gress while it’s fetch­ing ar­ti­facts from Maven re­pos­it­or­ies, but I was al­ways won­der­ing why you can­not use the same func­tion­al­ity when you’re down­load­ing ar­bit­rary files in your build script. You can of course use An­t’s down­load task to fetch files, but it does not dis­play pro­gress in­form­a­tion. Since I could­n’t find a solu­tion on the In­ter­net I de­cided to write a plug­in.

gradle-down­load-task has ini­tially been re­leased in Septem­ber 2013 and is now avail­able in ver­sion 5.0.0. The plug­in con­trib­utes a down­load task that shows pro­gress in­form­a­tion just like Gradle does when it fetches ar­ti­facts from a re­pos­it­ory.

You can use it like this:

task downloadFile(type: Download) {
    src 'https://download.blender.org/peach/bigbuckbunny_movies/big_buck_bunny_720p_stereo.ogg'
    dest buildDir
}

The out­put will look like this:

screencast.svg

In or­der to use the plug­in you have to add the fol­low­ing lines to your build file:

plugins {
    id "de.undercouch.download" version "5.0.0"
}

You can also use the down­load ex­ten­sion to re­trieve a file any­where in your build script:

apply plugin: 'download-task'

task myTask {
    doLast {
        // do something ...
        // ... then download a file
        download.run {
            src 'http://www.example.com/index.html'
            dest buildDir
        }
        // ... do something else
    }
}

You can also down­load a list of files to a dir­ect­ory. Please note that you have to spe­cify a dir­ect­ory as des­tin­a­tion if you down­load mul­tiple files. Oth­er­wise the plug­in will fail. Since gradle-down­load-task 5.0.0 the down­loads will be per­formed in par­al­lel.

task downloadMultipleFiles(type: Download) {
    src([
        'http://www.example.com/index.html',
        'http://www.example.com/test.html'
    ])
    dest buildDir
}

The plug­in sup­ports a wide range of other op­tions. Please read the README file for more in­form­a­tion.

Happy down­load­ing!

Sponsor this project

If you or your com­pany use any of my pro­jects or like what I’m do­ing, please con­sider spon­sor­ing me so I can con­tinue main­tain­ing and de­vel­op­ing my pro­jects and new ones!

Thank you so much for your sup­port!


Posted by Michel Krämer
on March, 22nd 2014.


Next post

bson4jackson 2.4 has just been released!

Ver­sion 2.4 of bson4­jack­son has just been re­leased. bson4­jack­son adds sup­port for BSON, a bin­ary rep­res­ent­a­tion of JSON, to the Jack­son JSON pro­cessor.

Previous post

Command line tool for citations and bibliographies

I was work­ing very hard on the new ver­sion of cite­proc-java lately and I’m glad to an­nounce that it has just been re­leased. The high­lights in ver­sion 0.6 are:

Related posts

10 recipes for gradle-download-task

I re­ceived a couple of re­quests lately con­cern­ing com­mon prob­lems when down­load­ing files in Gradle build scripts us­ing gradle-down­load-task. Al­most all of…

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…

New major version 4.0.0 of gradle-download-task

Today, I’m happy to an­nounce the new ma­jor ver­sion 4.0.0 of the pop­u­lar gradle-down­load-task. With this Gradle plug­in, you can down­load files in your build…


About Joyk


Aggregate valuable and interesting links.
Joyk means Joy of geeK