Download files in your Gradle build script with style progress and in parallel
This is a download task for Gradle.
It displays progress information just like Gradle does when it retrieves
an artifact from a repository. It is also able to download multiple files in
parallel and supports concurrent execution with other tasks.
The plugin has been successfully tested with Gradle 5.0 up to 7.4.2.
It should work with newer versions as well.
Want to be listed here? Just comment on this issue.
Usage
First, apply the plugin configuration:
plugins {
id "de.undercouch.download" version "5.1.0"
}
Then, use the Download task as follows:
task downloadFile(type: Download) {
src 'http://www.example.com/index.html'
dest buildDir
}
By default, the plugin always performs a download even if the destination file
already exists. If you want to prevent files from being downloaded again, use
the overwrite flag (see description below).
Note that this feature depends on the server and whether it supports the
If-Modified-Since request header and provides a Last-Modified
timestamp in its response.
Concurrently download a list of files to a directory
The download task and the extension support the following properties.
General
src
The URL from which to retrieve the file. Can be a list of URLs if
multiple files should 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)
onlyIfModified (alias: onlyIfNewer)
true if the file should only be downloaded if it
has been modified on the server since the last download (default:
false)
Tip! You may provide Groovy Closures or Kotlin Lambdas to the src
and dest properties to calculate their value at runtime.
Connection
acceptAnyCertificate
true if HTTPS certificate verification errors should be ignored
and any certificate (even an invalid one) should be accepted.
(default: false)
compress
true if compression should be used during download (default:
true)
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)
connectTimeout
The maximum number of milliseconds to wait until a connection is established.
A value of 0 (zero) means infinite timeout. A negative value
is interpreted as undefined. (default: 30 seconds)
readTimeout
The maximum time in milliseconds to wait for data from the server.
A value of 0 (zero) means infinite timeout. A negative value
is interpreted as undefined. (default: 30 seconds)
retries
Specifies the maximum number of retry attempts if a request has failed.
By default, requests are never retried and the task fails immediately if the
first request does not succeed. If the value is greater than 0,
failed requests are retried regardless of the actual error. This includes
failed connection attempts and file-not-found errors (404). A negative value
means infinite retries. (default: 0)
Authentication
username
The username that should be used if the server requires authentication
(optional)
password
The password that should be used if the server requires authentication
(optional)
preemptiveAuth
true if preemptive Basic authentication should be enabled.
By default, gradle-download-task automatically detects the required
authentication scheme by sending two requests: one without credentials to
determine the scheme based on the WWW-Authenticate header in the
server's response and the actual request with credentials. This will fail if the
server does not send a WWW-Authenticate header. In this case, set
preemptiveAuth to true to use Basic authentication
and to always send credentials in the first request. Note:
Sending credentials in clear text in the first request without checking if the
server actually needs them might pose a security risk. (default:
false)
Advanced
downloadTaskDir
The directory where the plugin stores information that should persist
between builds. It will only be created if necessary.
(default: ${buildDir}/download-task)
tempAndMove
true if the file should be downloaded to a temporary location
and, upon successful execution, moved to the final location. If
overwrite is set to false, this flag is useful to
avoid partially downloaded files if Gradle is forcefully closed or the system
crashes. Note that the plugin always deletes partial downloads on connection
errors, regardless of the value of this flag. The default temporary location
can be configured with the downloadTaskDir property. (default:
false)
useETag
Use this flag in combination with onlyIfModified. If both
flags are true, the plugin will check a file’s timestamp as well
as its entity tag (ETag) and only download it if it has been modified on the
server since the last download. The plugin can differentiate between
strong and weak
ETags. Possible values are:
false(default)
Do not use the ETag
true
Use the ETag but display a warning if it is weak
"all"
Use the ETag and do not display a warning if it is weak
"strongOnly"
Only use the ETag if it is strong
cachedETagsFile
The location of the file that keeps entity tags (ETags) received
from the server. (default: ${downloadTaskDir}/etags.json)
Verify task
The plugin also provides a Verify task that can be used to check the integrity
of a downloaded file by calculating its checksum and comparing it to a
pre-defined value. The task succeeds if the file’s checksum equals the
given value and fails if it doesn’t.
The verify task supports the following properties:
src
The file to verify (required)
checksum
The actual checksum to verify against (required)
algorithm
The algorithm to use to compute the checksum. See the
list of algorithm names
for more information. (default: MD5)
Proxy configuration
You can configure a proxy server by setting standard JVM system properties. The
plugin uses the same system properties as Gradle. You can set them in the build
script directly. For example, the proxy host can be set as follows:
gradle-download-task 5.0.0 introduces the following breaking changes:
The authScheme property has been removed. The plugin now automatically
detects the correct scheme to use based on the server response.
The download extension was incompatible with Gradle 8. Also, using it
from Kotlin build scripts was rather inconvenient. It is therefore now
necessary to call the extension through its run method. Replace
download { ... } with download.run { ... }. The same applies to the
verify extension.
Migrating from version 3.x to 4.x
In gradle-download-task 4.x, we made the following breaking changes to the
API:
The plugin now requires Gradle 2.x (or higher) and Java 7 (or higher)
We removed the timeout property and introduced connectTimeout and
readTimeout instead. This allows you to control the individual timeouts
better. Also, it improves compatibility with Gradle 5.x, where all tasks have
a timeout property by default.
The credentials property has been removed. The same applies to the
possibility to pass instances of Apache HttpClient’s AuthScheme to the
authScheme property. The strings Basic and Digest are now the only
accepted values. There is no replacement. If you need this functionality,
please file an issue.
The properties requestInterceptor and responseInterceptor have been
removed. There is no replacement. Again, if you need this functionality,
please file an issue.
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.
请发表评论