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:
Property | Default | Description |
---|---|---|
|
- |
The HTTP or HTTPS URL from which to download. This is mandatory |
|
- |
Destination file. This is mandatory, and can be anything that is understood by the Project.file(path) method. |
|
30000 (30 seconds) |
Milliseconds before timing out the connection attempt. Set to zero to disable the timeout (infinite timeout). |
|
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.