当前位置: 首页 > 软件库 > 应用工具 > 下载工具 >

gradle-download-task

授权协议 Apache-2.0 License
开发语言 Java
所属分类 应用工具、 下载工具
软件类型 开源软件
地区 不详
投 递 者 章誉
操作系统 跨平台
开源组织
适用人群 未知
 软件概览

Gradle Download Task Actions Status

This is a download task for Gradle.It displays progress information just as Gradle does when it retrievesan artifact from a repository.

The plugin has been successfully tested with Gradle 2.0 up to 7.1.1.It should work with newer versions as well.

Apply plugin configuration

Gradle 2.1 and higher

plugins {
    id "de.undercouch.download" version "4.1.2"
}

Gradle 2.0

buildscript {
    repositories {
        maven {
            url "https://plugins.gradle.org/m2/"
        }
    }
    dependencies {
        classpath 'de.undercouch:gradle-download-task:4.1.2'
    }
}

apply plugin: 'de.undercouch.download'

Usage

After you have applied the plugin configuration (see above), you can use theDownload 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 filealready exists. If you want to prevent files from being downloaded again, usethe overwrite flag (see description below).

task downloadFile(type: Download) {
    src 'http://www.example.com/index.html'
    dest buildDir
    overwrite false
}

As an alternative to the Download task, you may also use the downloadextension to retrieve a file anywhere in your build script:

task myTask {
    doLast {
        //do something ...
        //... then download a file
        download {
            src 'http://www.example.com/index.html'
            dest buildDir
            overwrite false
        }
        //... do something else
    }
}

Minimum requirements

The plugin requires:

  • Gradle 2.x or higher
  • Java 7 or higher

If you need to run the plugin with Gradle 1.x or Java 6, usegradle-download-task version 3.4.3.

Examples

Only download a file if it has been modified on the server

task downloadFile(type: Download) {
    src 'http://www.example.com/index.html'
    dest buildDir
    onlyIfModified true
}

Note that this feature depends on the server and whether it supports theIf-Modified-Since request header and provides a Last-Modifiedtimestamp in its response.

Sequentially download a list of files to a directory

task downloadMultipleFiles(type: Download) {
    src([
        'http://www.example.com/index.html',
        'http://www.example.com/test.html'
    ])
    dest buildDir
}

Please note that you have to specify a directory as destination if youdownload multiple files. Otherwise, the plugin will fail.

Download files from a directory

If you want to download all files from a directory and the serverprovides a simple directory listing, you can use the following code:

task downloadDirectory {
    doLast {
        def dir = 'http://central.maven.org/maven2/de/undercouch/gradle-download-task/1.0/'
        def urlLister = new org.apache.ivy.util.url.ApacheURLLister()
        def files = urlLister.listFiles(new URL(dir))
        download {
           src files
           dest buildDir
        }
    }
}

Download and extract a ZIP file

To download and unpack a ZIP file, you can combine the download taskplugin with Gradle's built-in support for ZIP files:

task downloadZipFile(type: Download) {
    src 'https://github.com/michel-kraemer/gradle-download-task/archive/1.0.zip'
    dest new File(buildDir, '1.0.zip')
}

task downloadAndUnzipFile(dependsOn: downloadZipFile, type: Copy) {
    from zipTree(downloadZipFile.dest)
    into buildDir
}

More examples

Please have a look at the examples directory for more code samples. You canalso read my blog post aboutcommon recipes for gradle-download-task.

Download task

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 ifmultiple 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 ithas been modified on the server since the last download (default:false)

Tip! You may provide Groovy Closures to the src and destproperties to calculate their value at runtime.

Connection

acceptAnyCertificate
true if HTTPS certificate verification errors should be ignoredand 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 downloadrequest (optional)
headers
A map of request headers to set when making the downloadrequest (optional)
connectTimeout
The maximum number of milliseconds to wait until a connection is established.A value of 0 (zero) means infinite timeout. A negative valueis 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 valueis 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 thefirst request does not succeed. If the value is greater than 0,failed requests are retried regardless of the actual error. This includesfailed connection attempts and file-not-found errors (404). A negative valuemeans infinite retries. (default: 0)

Authentication

username
The username for Basic or Digest authentication (optional)
password
The password for Basic or Digest authentication (optional)
authScheme
The authentication scheme to use (valid values are Basic and Digest). If username and password areset, the default value of this property will be Basic. Otherwise,this property has no default value. (optional)

Advanced

downloadTaskDir
The directory where the plugin stores information that should persistbetween builds. It will only be created if necessary. (default: ${buildDir}/download-task)
tempAndMove
true if the file should be downloaded to a temporary locationand, upon successful execution, moved to the final location. If overwrite is set to false, this flag is useful toavoid partially downloaded files if Gradle is forcefully closed or the systemcrashes. Note that the plugin always deletes partial downloads on connectionerrors, regardless of the value of this flag. The default temporary locationcan be configured with the downloadTaskDir property. (default:false)
useETag
Use this flag in combination with onlyIfModified. If bothflags are true, the plugin will check a file's timestamp as wellas its entity tag (ETag) and only download it if it has been modified on theserver since the last download. The plugin can differentiate between strong and weakETags. 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) receivedfrom the server. (default: ${downloadTaskDir}/etags.json)

Verify task

The plugin also provides a Verify task that can be used to check the integrityof a downloaded file by calculating its checksum and comparing it to apre-defined value. The task succeeds if the file's checksum equals thegiven value and fails if it doesn't.

Use the task as follows:

task verifyFile(type: Verify) {
    src new File(buildDir, 'file.ext')
    algorithm 'MD5'
    checksum 'ce114e4501d2f4e2dcea3e17b546f339'
}

You can combine the download task and the verify task as follows:

task downloadFile(type: Download) {
    src 'http://www.example.com/index.html'
    dest buildDir
}

task verifyFile(type: Verify, dependsOn: downloadFile) {
    src new File(buildDir, 'index.html')
    algorithm 'MD5'
    checksum '09b9c392dc1f6e914cea287cb6be34b0'
}

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 namesfor more information. (default: MD5)

Proxy configuration

You can configure a proxy server by setting standard JVM system properties. Theplugin uses the same system properties as Gradle. You can set them in the buildscript directly. For example, the proxy host can be set as follows:

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

Alternatively, you can set the properties in a gradle.properties file likethis:

systemProp.http.proxyHost=www.somehost.org
systemProp.http.proxyPort=8080
systemProp.http.proxyUser=userid
systemProp.http.proxyPassword=password
systemProp.http.nonProxyHosts=*.nonproxyrepos.com|localhost

Put this file in your project's root directory or in your Gradle home directory.

HTTPS is also supported:

systemProp.https.proxyHost=www.somehost.org
systemProp.https.proxyPort=8080
systemProp.https.proxyUser=userid
systemProp.https.proxyPassword=password
systemProp.https.nonProxyHosts=*.nonproxyrepos.com|localhost

Migrating from version 3.x to 4.x

In gradle-download-task 4.x, we made the following breaking changes to theAPI:

  • The plugin now requires Gradle 2.x (or higher) and Java 7 (or higher)
  • We removed the timeout property and introduced connectTimeout andreadTimeout instead. This allows you to control the individual timeoutsbetter. Also, it improves compatibility with Gradle 5.x, where all tasks havea timeout property by default.
  • The credentials property has been removed. The same applies to thepossibility to pass instances of Apache HttpClient's AuthScheme to theauthScheme property. The strings Basic and Digest are now the onlyaccepted values. There is no replacement. If you need this functionality,please file an issue.
  • The properties requestInterceptor and responseInterceptor have beenremoved. There is no replacement. Again, if you need this functionality,please file an issue.

License

The plugin is licensed under theApache License, Version 2.0.

Unless required by applicable law or agreed to in writing, softwaredistributed 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 andlimitations under the License.

  • https://github.com/michel-kraemer/gradle-download-task 用法在readme中已经讲的很清楚了,我主要介绍下注意事项吧。 我用这个插件的目的是为了让我的gradle项目在构建过程中从网上自动下载某个jar包,而不是手动拷贝。 那么如何把download task加到我们的构建周期中去呢? 很简单,你想把这个过程加到哪个gradle task之前,

  • Android自动化构建之使用Gradle下载与处理文件 一般情况下,我们的项目构建并不需要再去导入其他文件。但如果自己项目正在维护一个自己的library module,而这个library内又维护着大量会经常更新的SO库,SO库文件很小倒无所谓,但是SO库又多又大时,直接将SO库放入Git中,一个版本更新下来,Git库估计就要炸掉了。而此时,我们利用Gradle的task来执行下载与导入即可解

  • http://download.csdn.net/download/yongheng289/10039982       gradle-4.1-all.zip离线包下载 极速 android studio2.3 3.0编译必备 2017-10-26 上传大小:83.36MB  gradle-4.1 4.1-all studio gradle     下载后须解压,有俩文件,gradle-4.1-a

  • Gradle 7.3.3 发布 Gradle团队很兴奋地宣布Gradle 7.3.3。 此次发布引入声明性测试套件API对于JVM项目,添加支持用Java 17构建项目,并更新Scala插件以支持Scala 3. 此外,还会对构建进行更改更可靠,提供下载依赖项时ide的附加细节,提高自定义插件中未跟踪的文件,几个错误修复还有更多。 下载连接:点击进入快速下载 已修复问题 v7.3.3 版本中修复的

  • 如何解决Android Studio 3.1.3 Gradle同步错误无法下载Gradle-Core.jar? 尝试将以下内容google()作为第一个回购。不要把它放在jcenter()和mavenCentral()你现有的Android Studio项目。 repositories { google() // make this repo as the first one if Android

  • Android Studio 项目Gradle构建失败异常一:报错如下: Error:A problem occurred configuring project ':app'.> Could not resolve all dependencies for configuration ':app:classpath'.> Could not download gradle.jar (io.f

  • Android自动化构建之使用Gradle下载与处理文件 一般情况下,我们的项目构建并不需要再去导入其他文件。但如果自己项目正在维护一个自己的library module,而这个library内又维护着大量会经常更新的SO库,SO库文件很小倒无所谓,但是SO库又多又大时,直接将SO库放入Git中,一个版本更新下来,Git库估计就要炸掉了。而此时,我们利用Gradle的task来执行下载与导入即可解

  • 想必各位从Maven 转过来的大佬们,对于maven中配置国内仓库的方法还记忆深刻。通过/用户目录下/.m2/settings.xml 局部配置或者修改全局配置。不过没有接触过maven 也不要紧,可以参考本人的Maven深入学习教程 废话不多说。 步骤一:进入GRADLE_USER_HOME 一般情况下是C:\Users\Administrator.gradle\这个目录,如果你还没有配置过,这

  • gradle的二进制版本 创建有用的应用程序后,很可能我们想与其他人共享它。 一种方法是创建一个可以从我们的网站下载的二进制发行版。 这篇博客文章描述了如何满足以下要求的二进制发行版: 我们的二进制分发不得使用所谓的“胖子”方法。 换句话说,我们的应用程序的依赖项不得与我们的应用程序打包到同一jar文件中。 我们的二进制发行版必须包含* nix和Windows操作系统的启动脚本。 我们的二进制发行

  • 预备知识 理解 gradle 的基本开发 了解 gradle task 和 plugin 使用及开发 了解 android gradle plugin 的使用 看完本文可以达到什么程度 了解 gradle 的实现原理 阅读前准备工作 clone EasyGradle 项目 下载 Gradle 源码 作为参考 读代码的姿势 调用链路,方便读代码时对照 集中于整体框架,一些细节不做追究 目录 本文主要

  • 创建一个kotlin语言的android项目,项目的根目录下的build.gradle中会自动添加: classpath "org.jetbrains.kotlin:kotlin-gradle-plugin:$kotlin_version" 如: // Top-level build file where you can add configuration options common to a

  • 解决gradle:download特别慢的问题 参考文章: (1)解决gradle:download特别慢的问题 (2)https://www.cnblogs.com/zhang-cb/p/6065118.html (3)https://www.codeprj.com/blog/5c8bde1.html 备忘一下。

  • Gradle 下载失败的问题解决 错误提示如下: Could not install Gradle distribution from 'https://services.gradle.org/distributions/gradle-XXXX… 解决 第一步 方法一:直接复制链接到浏览器下载 xxx.zip 文件 方法二:浏览器打开 https://gradle.org/releases/ 并找

  • 使用 gradle-5.1.1-all.zip com.android.tools.build:gradle:3.4.2 添加 'com.squareup.retrofit2:converter-gson:2.0.2'总是无法下载 Unable to resolve dependency for ':app@ReleasesDebug/compileClasspath': Could n

  • apply plugin: 'java' sourceCompatibility = 1.8 repositories { maven { url "http://maven.xx" } } dependencies { compile 'io.spring.gradle:dependency-management-plugin:0.6.1.RELEASE'

  • 1.3从命令行执行Gradle构建 问题 您希望从命令行运行Gradle任务。 解 从命令行,使用提供的Gradle包装器或安装Gradle并直接运行它。 讨论 你不需要安装Gradle来构建Android项目。 Android Studio附带了Gradle发行版(以插件的形式),并包含支持它的专用功能。 术语“Gradle包装器”是指在Android应用程序的根目录中的Unix和gradlew

  • https://maven.aliyun.com/mvn/guide 仓库名称 阿里云仓库地址 阿里云仓库地址(老版) 源地址 central https://maven.aliyun.com/repository/central https://maven.aliyun.com/nexus/content/repositories/central https://repo1.maven.org/

 相关资料
  • Tengine-2.3.3.tar.gz MD5: 01651b1342c406b933490dd8f2962b36 Tengine-2.3.2.tar.gz MD5: d854a6ecb3f0e140d94d9e0c45044d1e Tengine-2.3.1.tar.gz MD5: c015bff33bd283e0293b64d870d2096a Tengine-2.3.0.tar.gz MD

  • Read-only Subversion repositories: code: svn://svn.nginx.org/nginx site: svn://svn.nginx.org/nginx.org Trac source browser Pre-Built Linux Packages for Stable To enable automatic updates of Linux pack

  • Read-only Subversion repositories: code: svn://svn.nginx.org/nginx Read-only Mercurial repositories: site: http://hg.nginx.org/nginx.org Trac source browser Pre-Built Linux Packages for Stable To enab

  • 用过 Flashget 的都知道它有一个批量下载功能,用来下载一组类似的 url 非常方便。所以闲来无事,就开发了这个有类似功能的扩展,它比 Flashget 的批量下载功能好的地方是可以突破一些防盗链的下载网站,尤其是一些图片网站。感兴趣的朋友可以装上备用。

  • 当您点击一个 PDF 连接时会弹出一个对话框,让您选择是在标签页中打开还是下载它,打开后的文件格式可以选择 pdf 或者 html 。

  • Download Indicator 实现三种圆形的进度条。一种是圆环型,一种是实心圆形,一种是圆环加实心圆。进度条的动画效果也有两种,一种是连续前进,一种是分段前进,具体看效果图。可用作下载进度指示器。