gradle-download-task: download files with progress
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.
gradle-download-task: download files with progress
I really like how Gradle displays progress while it’s fetching artifacts from Maven repositories, but I was always wondering why you cannot use the same functionality when you’re downloading arbitrary files in your build script. You can of course use Ant’s download task to fetch files, but it does not display progress information. Since I couldn’t find a solution on the Internet I decided to write a plugin.
gradle-download-task has initially been released in September 2013 and is now available in version 5.0.0. The plugin contributes a download task that shows progress information just like Gradle does when it fetches artifacts from a repository.
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 output will look like this:
In order to use the plugin you have to add the following lines to your build file:
plugins {
id "de.undercouch.download" version "5.0.0"
}
You can also use the download extension to retrieve a file anywhere 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 download a list of files to a directory. Please note that you have to specify a directory as destination if you download multiple files. Otherwise the plugin will fail. Since gradle-download-task 5.0.0 the downloads will be performed in parallel.
task downloadMultipleFiles(type: Download) {
src([
'http://www.example.com/index.html',
'http://www.example.com/test.html'
])
dest buildDir
}
The plugin supports a wide range of other options. Please read the README file for more information.
Happy downloading!
Sponsor this project
If you or your company use any of my projects or like what I’m doing, please consider sponsoring me so I can continue maintaining and developing my projects and new ones!
Thank you so much for your support!
Next post
bson4jackson 2.4 has just been released!
Version 2.4 of bson4jackson has just been released. bson4jackson adds support for BSON, a binary representation of JSON, to the Jackson JSON processor.
Previous post
Command line tool for citations and bibliographies
I was working very hard on the new version of citeproc-java lately and I’m glad to announce that it has just been released. The highlights in version 0.6 are:
Related posts
10 recipes for gradle-download-task
I received a couple of requests lately concerning common problems when downloading files in Gradle build scripts using gradle-download-task. Almost all of…
New features in gradle-download-task 3.4.0
The new version 3.4.0 of gradle-download-task, a Gradle plugin providing a Download
task that display progress information, has just been released. It contains…
New major version 4.0.0 of gradle-download-task
Today, I’m happy to announce the new major version 4.0.0 of the popular gradle-download-task. With this Gradle plugin, you can download files in your build…
Recommend
About Joyk
Aggregate valuable and interesting links.
Joyk means Joy of geeK