Ecosyste.ms: Awesome

An open API service indexing awesome lists of open source software.

Awesome Lists | Featured Topics | Projects

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

A parallel download task type for Gradle
https://github.com/vmj/gradle-download-worker

download get gradle gradle-plugin groovy groovy-language http parallel worker

Last synced: about 5 hours ago
JSON representation

A parallel download task type for Gradle

Awesome Lists containing this project

README

        

= A parallel download task type for Gradle

image:https://travis-ci.org/vmj/gradle-download-worker.svg?branch=master["Build Status", link="https://travis-ci.org/vmj/gradle-download-worker"]

This Gradle plugin implements a parallel download task type.

The releases are available via
https://search.maven.org/artifact/fi.linuxbox.gradle/gradle-download/0.6/jar[Maven Central],
https://bintray.com/bintray/jcenter/fi.linuxbox.gradle%3Agradle-download[Bintray], and
https://plugins.gradle.org/plugin/fi.linuxbox.download[Gradle Plugin Portal].

Plugin version 0.7 requires *Gradle 5.6 or newer* (tested up to 8.7).
Version 0.6 supports Gradle versions 5.0 - 7.6.
If you need to use older Gradle (down to 4.3), use version 0.5 of the plugin.

== Usage

Basic usage is as follows:

[source,groovy]
----
plugins {
id 'fi.linuxbox.download' version '0.7'
}

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:

[source,groovy]
----
plugins {
id 'fi.linuxbox.download' version '0.7'
}

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:

.Configuration properties
[cols="2,2,6"]
|===
|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
https://docs.gradle.org/current/dsl/org.gradle.api.Project.html#org.gradle.api.Project:file(java.lang.Object)[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:

[source,groovy]
----
dependencies {
compile 'fi.linuxbox.gradle:gradle-download:0.7'
}
----

And a Maven equivalent is:

[source,xml]
----

fi.linuxbox.gradle
gradle-download
0.7

----

This is relevant if you are applying the plugin via
https://docs.gradle.org/current/javadoc/org/gradle/api/plugins/PluginContainer.html#apply-java.lang.Class-[PluginContainer.apply(Class)]
method.