gradle-download-task

repository·master·Indexed 20 days ago

https://github.com/michel-kraemer/gradle-download-task

A Gradle plugin providing advanced file downloading capabilities. Features include parallel downloads, progress bars, conditional downloads using ETags or modification timestamps, mirror server support, and checksum verification via the Verify task. It supports downloading single or multiple files, fetching directory contents (including GitHub API integration), and custom HTTP headers. Compatible with Gradle 5.x+ and Java 8+, with version 4.1.2 available for older environments.

Tokens
3.5K
Snippets
19
Records
21
Agent score
22%

What's inside gradle-download-task

  1. Download files conditionally based on server modification

    master

    You can optimize builds by only downloading a file if it has changed on the server.

    • Use onlyIfModified true to check the If-Modified-Since header. This requires the server to provide a Last-Modified timestamp.
    • Use onlyIfModified true in combination with useETag if the server supports entity tags (ETags).
    task downloadFile(type: Download) {
        src 'http://www.example.com/index.html'
        dest layout.buildDirectory
        onlyIfModified true
    }
  2. Configure proxy settings

    master

    The plugin uses standard JVM system properties for proxy configuration. You can set these in your build script or via a gradle.properties file.

    In build script:

    System.setProperty("http.proxyHost", "www.somehost.org")

    In gradle.properties:

    systemProp.http.proxyHost=www.somehost.org
    systemProp.http.proxyPort=8080
    systemProp.http.proxyUser=userid
    systemProp.http.proxyPassword=password
    systemProp.http.nonProxyHosts=*.nonproxyrepos.com|localhost
  3. Migrate from version 4.x to 5.x

    master

    Version 5.0.0 introduced the following breaking changes:

    • authScheme removed: The plugin now automatically detects the correct scheme based on the server response.
    • download extension usage: The download extension is no longer compatible with Gradle 8 and is inconvenient in Kotlin scripts. You must now call the extension through its .run method.
      • Old: download { ... }
      • New: download.run { ... }
      • This applies to both the download and verify extensions.
  4. Use the Download task

    master

    The Download task type allows you to retrieve files during the Gradle build process. You can specify a source URL and a destination file or directory.

    By default, the plugin overwrites existing files. Set overwrite false to prevent re-downloading if the file already exists.

    task downloadFile(type: Download) {
        src 'http://www.example.com/index.html'
        dest layout.buildDirectory
    }
  5. Download multiple files concurrently

    master

    To download a list of files in parallel, provide a list of URLs to the src property.

    Requirement: When downloading multiple files, the dest property must be a directory. If you specify a file as the destination for multiple sources, the plugin will fail.

    task downloadMultipleFiles(type: Download) {
        src([
            'http://www.example.com/index.html',
            'http://www.example.com/test.html'
        ])
        dest layout.buildDirectory
    }
  6. Verify file integrity with checksums

    master

    To ensure a downloaded file is not corrupted, use the verification features. You can either use a dedicated Verify task or the verifyChecksum extension to calculate the file's checksum and compare it against a known expected value.

    // See groovy/verify/build.gradle or groovy/verify-extension/build.gradle
  7. Download and extract a ZIP file

    master

    To download and unpack a ZIP file, combine the Download task with Gradle's built-in Copy task and zipTree function.

    task downloadZipFile(type: Download) {
        src 'https://github.com/michel-kraemer/gradle-download-task/archive/refs/tags/5.7.0.zip'
        dest layout.buildDirectory.file('5.7.0.zip')
    }
    
    task downloadAndUnzipFile(dependsOn: downloadZipFile, type: Copy) {
        from zipTree(downloadZipFile.dest)
        into layout.buildDirectory
    }