gradle-download

This plugin provides a Download task type for Gradle. Tasks of this type can do HTTP and HTTPS downloads in parallel.

License

License

Categories

Categories

Gradle Build Tools
GroupId

GroupId

fi.linuxbox.gradle
ArtifactId

ArtifactId

gradle-download
Last Version

Last Version

0.6
Release Date

Release Date

Type

Type

jar
Description

Description

gradle-download
This plugin provides a Download task type for Gradle. Tasks of this type can do HTTP and HTTPS downloads in parallel.
Project URL

Project URL

https://github.com/vmj/gradle-download-worker
Source Code Management

Source Code Management

https://github.com/vmj/gradle-download-worker

Download gradle-download

How to add to project

<!-- https://jarcasting.com/artifacts/fi.linuxbox.gradle/gradle-download/ -->
<dependency>
    <groupId>fi.linuxbox.gradle</groupId>
    <artifactId>gradle-download</artifactId>
    <version>0.6</version>
</dependency>
// https://jarcasting.com/artifacts/fi.linuxbox.gradle/gradle-download/
implementation 'fi.linuxbox.gradle:gradle-download:0.6'
// https://jarcasting.com/artifacts/fi.linuxbox.gradle/gradle-download/
implementation ("fi.linuxbox.gradle:gradle-download:0.6")
'fi.linuxbox.gradle:gradle-download:jar:0.6'
<dependency org="fi.linuxbox.gradle" name="gradle-download" rev="0.6">
  <artifact name="gradle-download" type="jar" />
</dependency>
@Grapes(
@Grab(group='fi.linuxbox.gradle', module='gradle-download', version='0.6')
)
libraryDependencies += "fi.linuxbox.gradle" % "gradle-download" % "0.6"
[fi.linuxbox.gradle/gradle-download "0.6"]

Dependencies

test (1)

Group / Artifact Type Version
junit : junit jar 4.12

Project Modules

There are no modules declared in this project.

Build Status

A parallel download task type for Gradle

This Gradle plugin implements a parallel download task type.

The releases are available via Maven Central, Bintray, and Gradle Plugin Portal.

Plugin version 0.6 requires Gradle 5.0 or newer. If you need to use older Gradle (down to 4.3), use version 0.5 of the plugin.

Usage

Basic usage is as follows:

plugins {
    id 'fi.linuxbox.download' version '0.6'
}

import fi.linuxbox.gradle.download.Download

task("my-download", type: Download) {
    from 'https://www.google.com/robots.txt'
    to "$buildDir/robots.txt"
}

A more interesting example:

plugins {
    id 'fi.linuxbox.download' version '0.6'
}

import fi.linuxbox.gradle.download.Download

final downloadAll = tasks.register('downloadAll') {
    group 'My tasks'
    description 'Download all ChangeLogs'
}

ext {
    mirror = 'http://ftp.osuosl.org/pub/slackware'
    distroNames = ['slackware', 'slackware64']
    distroVersions = ['13.0', '13.1', '13.37', '14.0', '14.1', '14.2']
}

distroNames.each { final distroName ->
    distroVersions.each { final distroVersion ->
        final distro = "$distroName-$distroVersion"
        final path = "$distroName/$distroVersion"

        // Define a parallel download task for this distro version
        final download = tasks.register("download-$distro-changelog", Download) {
            from "$mirror/$distro/ChangeLog.txt"
            to "$buildDir/changelogs/$path/ChangeLog.txt"
        }

        // Just to demo the UP-TO-DATE functionality:
        // even though the download task does some work (conditional GET)
        // it doesn't necessarily touch the artifact.
        // That allows Gradle to skip the copy task.
        final copy = tasks.register("copy-$distro-changelog", Copy) {
            from download
            into "$buildDir/copies/$path/"
        }

        downloadAll.configure {
            dependsOn copy
        }
    }
}

With above build script, the first run of gradle downloadAll would download the ChangeLog files in parallel. Then it would copy each ChangeLog as soon as it was downloaded, i.e. in parallel.

The second invocation of gradle downloadAll would finish pretty quickly, as the download task will make a conditional HTTP GET and, since the ChangeLogs will not be updated, copy tasks will report UP-TO-DATE.

Task Configuration

This download task can be configured with the following properties:

Table 1. Configuration properties
Property Default Description

from

-

The HTTP or HTTPS URL from which to download. This is mandatory

to

-

Destination file. This is mandatory, and can be anything that is understood by the Project.file(path) method.

connectTimeout

30000 (30 seconds)

Milliseconds before timing out the connection attempt. Set to zero to disable the timeout (infinite timeout).

readTimeout

30000 (30 seconds)

Milliseconds before timing out the socket reading. Set to zero to disable the timeout (infinite timeout).

Programmatic usage (rarely needed)

In case you are using this project as a library dependency (perhaps as part of another Gradle plugin), in Gradle that would look like:

dependencies {
    compile 'fi.linuxbox.gradle:gradle-download:0.6'
}

And a Maven equivalent is:

<dependency>
  <groupId>fi.linuxbox.gradle</groupId>
  <artifactId>gradle-download</artifactId>
  <version>0.6</version>
</dependency>

This is relevant if you are applying the plugin via PluginContainer.apply(Class) method.

Versions

Version
0.6
0.5