by michel-kraemer

michel-kraemer /gradle-download-task

Adds a download task to Gradle that displays progress information

453 Stars 62 Forks Last release: 3 months ago (4.1.1) Apache License 2.0 352 Commits 27 Releases

Available items

No Items, yet!

The developer of this repository has not created any items for sale yet. Need a bug fixed? Help with integration? A different license? Create a request here:

Gradle Download Task Actions Status codecov Apache License, Version 2.0

This is a download task for Gradle. It displays progress information just as Gradle does when it retrieves an artifact from a repository.

The plugin has been successfully tested with Gradle 2.0 up to 6.5. It should work with newer versions as well.

Apply plugin configuration

Gradle 2.1 and higher

plugins {
    id "" version "4.1.1"

Gradle 2.0

buildscript {
    repositories {
    dependencies {
        classpath 'de.undercouch:gradle-download-task:4.1.1'

apply plugin: ''


After you have applied the plugin configuration (see above), you can use the

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

By default, the plugin always performs a download even if the destination file already exists. If you want to prevent files from being downloaded again, use the

flag (see description below).
task downloadFile(type: Download) {
    src ''
    dest buildDir
    overwrite false

As an alternative to the

task, you may also use the
extension to retrieve a file anywhere in your build script:
task myTask {
    doLast {
        //do something ...
        //... then download a file
        download {
            src ''
            dest buildDir
            overwrite false
        //... do something else

Minimum requirements

The plugin requires:

  • Gradle 2.x or higher
  • Java 7 or higher

If you need to run the plugin with Gradle 1.x or Java 6, use gradle-download-task version 3.4.3.


Only download a file if it has been modified on the server

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

Note that this feature depends on the server and whether it supports the

request header and provides a
timestamp in its response.

Sequentially download a list of files to a directory

task downloadMultipleFiles(type: Download) {
    dest buildDir

Please note that you have to specify a directory as destination if you download multiple files. Otherwise, the plugin will fail.

Download files from a directory

If you want to download all files from a directory and the server provides a simple directory listing, you can use the following code:

task downloadDirectory {
    doLast {
        def dir = ''
        def urlLister = new org.apache.ivy.util.url.ApacheURLLister()
        def files = urlLister.listFiles(new URL(dir))
        download {
           src files
           dest buildDir

Download and extract a ZIP file

To download and unpack a ZIP file, you can combine the download task plugin with Gradle's built-in support for ZIP files:

task downloadZipFile(type: Download) {
    src ''
    dest new File(buildDir, '')

task downloadAndUnzipFile(dependsOn: downloadZipFile, type: Copy) { from zipTree(downloadZipFile.dest) into buildDir }

More examples

Please have a look at the

directory for more code samples. You can also read my blog post about common recipes for gradle-download-task.

Download task

The download task and the extension support the following properties.


The URL from which to retrieve the file. Can be a list of URLs if multiple files should be downloaded. (required)
The file or directory where to store the file (required)
true if progress information should not be displayed (default: false)
true if existing files should be overwritten (default: true)
onlyIfModified (alias: onlyIfNewer)
true if the file should only be downloaded if it has been modified on the server since the last download (default: false)

Tip! You may provide Groovy Closures to the

properties to calculate their value at runtime.


true if HTTPS certificate verification errors should be ignored and any certificate (even an invalid one) should be accepted. (default: false)
true if compression should be used during download (default: true)
The name and value of a request header to set when making the download request (optional)
A map of request headers to set when making the download request (optional)
The maximum number of milliseconds to wait until a connection is established. A value of 0 (zero) means infinite timeout. A negative value is interpreted as undefined. (default: 30 seconds)
The maximum time in milliseconds to wait for data from the server. A value of 0 (zero) means infinite timeout. A negative value is interpreted as undefined. (default: 30 seconds)
Specifies the maximum number of retry attempts if a request has failed. By default, requests are never retried and the task fails immediately if the first request does not succeed. If the value is greater than 0, failed requests are retried regardless of the actual error. This includes failed connection attempts and file-not-found errors (404). A negative value means infinite retries. (default: 0)


The username for Basic or Digest authentication (optional)
The password for Basic or Digest authentication (optional)
The authentication scheme to use (valid values are Basic and Digest). If username and password are set, the default value of this property will be Basic. Otherwise, this property has no default value. (optional)


The directory where the plugin stores information that should persist between builds. It will only be created if necessary. (default: ${buildDir}/download-task)
true if the file should be downloaded to a temporary location and, upon successful execution, moved to the final location. If overwrite is set to false, this flag is useful to avoid partially downloaded files if Gradle is forcefully closed or the system crashes. Note that the plugin always deletes partial downloads on connection errors, regardless of the value of this flag. The default temporary location can be configured with the downloadTaskDir property. (default: false)
Use this flag in combination with onlyIfModified. If both flags are true, the plugin will check a file's timestamp as well as its entity tag (ETag) and only download it if it has been modified on the server since the last download. The plugin can differentiate between strong and weak ETags. Possible values are:
false (default)
Do not use the ETag
Use the ETag but display a warning if it is weak
Use the ETag and do not display a warning if it is weak
Only use the ETag if it is strong
The location of the file that keeps entity tags (ETags) received from the server. (default: ${downloadTaskDir}/etags.json)

Verify task

The plugin also provides a

task that can be used to check the integrity of a downloaded file by calculating its checksum and comparing it to a pre-defined value. The task succeeds if the file's checksum equals the given value and fails if it doesn't.

Use the task as follows:

task verifyFile(type: Verify) {
    src new File(buildDir, 'file.ext')
    algorithm 'MD5'
    checksum 'ce114e4501d2f4e2dcea3e17b546f339'

You can combine the download task and the verify task as follows:

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

task verifyFile(type: Verify, dependsOn: downloadFile) { src new File(buildDir, 'index.html') algorithm 'MD5' checksum '09b9c392dc1f6e914cea287cb6be34b0' }

The verify task supports the following properties:

The file to verify (required)
The actual checksum to verify against (required)
The algorithm to use to compute the checksum. See the list of algorithm names for more information. (default: MD5)

Proxy configuration

You can configure a proxy server by setting standard JVM system properties. The plugin uses the same system properties as Gradle. You can set them in the build script directly. For example, the proxy host can be set as follows:

System.setProperty("http.proxyHost", "");

Alternatively, you can set the properties in a
file like this:

Put this file in your project's root directory or in your Gradle home directory.

HTTPS is also supported:

Migrating from version 3.x to 4.x

In gradle-download-task 4.x, we made the following breaking changes to the API:

  • The plugin now requires Gradle 2.x (or higher) and Java 7 (or higher)
  • We removed the
    property and introduced
    instead. This allows you to control the individual timeouts better. Also, it improves compatibility with Gradle 5.x, where all tasks have a
    property by default.
  • The
    property has been removed. The same applies to the possibility to pass instances of Apache HttpClient's
    to the
    property. The strings
    are now the only accepted values. There is no replacement. If you need this functionality, please file an issue.
  • The properties
    have been removed. There is no replacement. Again, if you need this functionality, please file an issue.


The plugin is licensed under the Apache License, Version 2.0.

Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the specific language governing permissions and limitations under the License.

We use cookies. If you continue to browse the site, you agree to the use of cookies. For more information on our use of cookies please see our Privacy Policy.