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. Of course, you can 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 see the README file for more information.

Happy downloading!

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!

Profile image of Michel Krämer

Sponsor Michel Krämer on GitHub Sponsors

Researcher, software developer, musician, and photographer. I love open source 🥳


Profile image of Michel Krämer

Posted by Michel Krämer
on 22 March 2014


Next post

bson4jackson 2.4 has just been released!

The latest release of bson4jackson now supports Jackson 2.4. Also, more deserializers have been added and a few minor bugs have been fixed. The update is recommended for all users.

Previous post

Command line tool for citations and bibliographies

Version 0.6 of citeproc-java introduces a command line tool that can be used to generate citations and bibliographies without setting up a complete development environment.

Related posts

10 recipes for gradle-download-task

gradle-download-task is a Gradle plugin that allows you to download files during the build process. This post summarizes common patterns and use cases of gradle-download-task and provides useful tips and tricks.

New major version 5.0.0 of gradle-download-task

I’ve just released gradle-download-task 5.0.0. The new version now downloads multiple files in parallel, executes concurrently with other build tasks, and offers better support for Kotlin and Gradle 8.

Build Scala projects with Eclipse Buckminster

Buckminster is a tool to build Eclipse RCP applications. It contains a lightweight Eclipse SDK and features but no means to build Scala projects yet. This post tries to bridge this gap.