gradle-download-task


Source link: https://github.com/michel-kraemer/gradle-download-task

Gradle Download Task

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

The plugin has been sucessfully tested with Gradle 1.0 up to 4.1. It should work with newer versions as well.

Apply plugin configuration

Gradle 2.1 and higher

plugins {

  id "de.undercouch.download" version "3.3.0" 
}

Gradle 1.x and 2.0

buildscript {

  repositories {

jcenter()
  
}

  dependencies {

classpath 'de.undercouch:gradle-download-task:3.3.0'
  
}
 
}
  apply plugin: 'de.undercouch.download'

Usage

After you applied the plugin configuration (see above) you can use the Download task as follows:

import de.undercouch.gradle.tasks.download.Download  task downloadFile(type: Download) {

  src 'http://www.example.com/index.html'
  dest buildDir 
}

You can also use the download extension to retrieve a file anywhere in your build script:

task myTask << {

  //do something ...
  //... then download a file
  download {

src 'http://www.example.com/index.html'

dest buildDir
  
}

  //... do something else 
}

Examples

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 you download multiple files. Otherwise the plugin will fail.

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

task downloadDirectory {

  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
  
}
 
}

To download and unpack a ZIP file you can combine the download task plugin 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 
}

Please have a look at the examples directory for more code samples.

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 if multiple files shoud 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 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)
timeout
The maximum time to wait until a connection is established or until the server returns data. A value of 0 (zero) means infinite timeout. A negative value is interpreted as undefined. (default: -1)

Authentication

username
The username for Basic or Digest authentication (optional)
password
The password for Basic or Digest authentication (optional)
credentials
The credentials to use for authentication. This property is an alternative to username and password. The value is expected to be an instance of Credentials. (optional)
authScheme
The authentication scheme to use. Either a string (valid values are Basic and Digest) or an instance of AuthScheme. If credentials are configured (either through username and password or through credentials) the default value of this property will be Basic. Otherwise this property has no default value. (optional)

Advanced

requestInterceptor
An instance of HttpRequestInterceptor. Can be used to intercept and modify outgoing HTTP requests before they are sent to the server. (optional)
responseInterceptor
An instance of HttpResponseInterceptor. Can be used to intercept and manipulate HTTP responses from the server before they are handled by the plugin. (optional)

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.

Use the task as follows:

import de.undercouch.gradle.tasks.download.Verify  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:

import de.undercouch.gradle.tasks.download.Download import de.undercouch.gradle.tasks.download.Verify  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 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:

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

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

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

License

The plugin is licensed under the Apache License, Version 2.0.

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.

Resources

Roaring RxJava. A collection of useful RxJava 2.X classes.

Loads images for Bypass using Picasso.

okio made easy, yo.

A Searchable Spinner with customizable color and a nice reveal animation.

The Sweetest way into connecting to your server. Now min SDK is 3!

This is an Image slider with swipes.

Topics


2D Engines   3D Engines   9-Patch   Action Bars   Activities   ADB   Advertisements   Analytics   Animations   ANR   AOP   API   APK   APT   Architecture   Audio   Autocomplete   Background Processing   Backward Compatibility   Badges   Bar Codes   Benchmarking   Bitmaps   Bluetooth   Blur Effects   Bread Crumbs   BRMS   Browser Extensions   Build Systems   Bundles   Buttons   Caching   Camera   Canvas   Cards   Carousels   Changelog   Checkboxes   Cloud Storages   Color Analysis   Color Pickers   Colors   Comet/Push   Compass Sensors   Conferences   Content Providers   Continuous Integration   Crash Reports   Credit Cards   Credits   CSV   Curl/Flip   Data Binding   Data Generators   Data Structures   Database   Database Browsers   Date &   Debugging   Decompilers   Deep Links   Dependency Injections   Design   Design Patterns   Dex   Dialogs   Distributed Computing   Distribution Platforms   Download Managers   Drawables   Emoji   Emulators   EPUB   Equalizers &   Event Buses   Exception Handling   Face Recognition   Feedback &   File System   File/Directory   Fingerprint   Floating Action   Fonts   Forms   Fragments   FRP   FSM   Functional Programming   Gamepads   Games   Geocaching   Gestures   GIF   Glow Pad   Gradle Plugins   Graphics   Grid Views   Highlighting   HTML   HTTP Mocking   Icons   IDE   IDE Plugins   Image Croppers   Image Loaders   Image Pickers   Image Processing   Image Views   Instrumentation   Intents   Job Schedulers   JSON   Keyboard   Kotlin   Layouts   Library Demos   List View   List Views   Localization   Location   Lock Patterns   Logcat   Logging   Mails   Maps   Markdown   Mathematics   Maven Plugins   MBaaS   Media   Menus   Messaging   MIME   Mobile Web   Native Image   Navigation   NDK   Networking   NFC   NoSQL   Number Pickers   OAuth   Object Mocking   OCR Engines   OpenGL   ORM   Other Pickers   Parallax List   Parcelables   Particle Systems   Password Inputs   PDF   Permissions   Physics Engines   Platforms   Plugin Frameworks   Preferences   Progress Indicators   ProGuard   Properties   Protocol Buffer   Pull To   Purchases   Push/Pull   QR Codes   Quick Return   Radio Buttons   Range Bars   Ratings   Recycler Views   Resources   REST   Ripple Effects   RSS   Screenshots   Scripting   Scroll Views   SDK   Search Inputs   Security   Sensors   Services   Showcase Views   Signatures   Sliding Panels   Snackbars   SOAP   Social Networks   Spannable   Spinners   Splash Screens   SSH   Static Analysis   Status Bars   Styling   SVG   System   Tags   Task Managers   TDD &   Template Engines   Testing   Testing Tools   Text Formatting   Text Views   Text Watchers   Text-to   Toasts   Toolkits For   Tools   Tooltips   Trainings   TV   Twitter   Updaters   USB   User Stories   Utils   Validation   Video   View Adapters   View Pagers   Views   Watch Face   Wearable Data   Wearables   Weather   Web Tools   Web Views   WebRTC   WebSockets   Wheel Widgets   Wi-Fi   Widgets   Windows   Wizards   XML   XMPP   YAML   ZIP Codes