Skip to content

Adds a download task to Gradle that displays progress information

License

Notifications You must be signed in to change notification settings

jeremymailen/gradle-download-task

 
 

Repository files navigation

Gradle Download Task Build Status

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

The plugin has been sucessfully tested with Gradle 1.0 up to 2.2.1. It should work with newer versions as well.

Apply plugin configuration

Gradle 2.1 and higher

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

Gradle 1.x and 2.0

buildscript {
    repositories {
        jcenter()
    }
    dependencies {
        classpath 'de.undercouch:gradle-download-task:1.2'
    }
}

apply plugin: 'de.undercouch.download'

Usage

After you applied the plugin configuration (see above) you can use the Download task as follows:

import de.undercouch.gradle.tasks.download.Download

task downloadFile(type: Download) {
    src 'http://www.example.com/index.html'
    dest buildDir
}

You can also use the download extension to retrieve a file anywhere in your build script:

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

Examples

Sequentially download a list of files to a directory:

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

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

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 {
    def dir = 'http://central.maven.org/maven2/de/undercouch/gradle-download-task/1.0/'
    def urlLister = new org.apache.ivy.util.url.ApacheURLLister()
    def files = urlLister.listFiles(new URL(dir))
    download {
       src files
       dest buildDir
    }
}

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

task downloadZipFile(type: Download) {
    src 'https://github.com/michel-kraemer/gradle-download-task/archive/1.0.zip'
    dest new File(buildDir, '1.0.zip')
}

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

Please have a look at the examples directory for more code samples.

Properties

The download task and the extension support the following properties

src
The URL from which to retrieve the file. Can be a list of URLs if multiple files shoud be downloaded. (required)
dest
The file or directory where to store the file (required)
quiet
true if progress information should not be displayed (default: false)
overwrite
true if existing files should be overwritten (default: true)
onlyIfNewer
true if the file should only be downloaded if it has been modified on the server since the last download (default: false)
compress
true if compression should be used during download (default: true)
username
The username for Basic authentication (optional)
password
The password for Basic authentication (optional)
header
The name and value of a request header to set when making the download request (optional)
headers
A map of request headers to set when making the download request (optional)

License

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.

About

Adds a download task to Gradle that displays progress information

Resources

License

Stars

Watchers

Forks

Packages

No packages published

Languages

  • Java 100.0%