Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

how to download external files in gradle?

Tags:

gradle

I have a gradle project which requires some data files available somewhere on the internet using http. The goal is that this immutable remote file is pulled once upon first build. Subsequent build should not download again.

How can I instruct gradle to fetch the given file to a local directory?

I've tried

task fetch(type:Copy) {    from 'http://<myurl>'    into 'data' } 

but it seems that copy task type cannot deal with http.

Bonus question: is there a way to resume a previously aborted/interrupted download just like wget -c does?

like image 987
Stefan Armbruster Avatar asked Jun 15 '13 12:06

Stefan Armbruster


People also ask

How do I UnZip a file in Gradle?

But there is no UnZip or UnTar to unpack an archive in Gradle. To unpack an archive we must use the Copy task and copy the contents of the archive to a specified destination directory. In Gradle we can use the zipTree() method to access the contents of an archive.

How do I import into Gradle?

Launch Android Studio, and click File > New > Import Project. Locate your project directory, click the build. gradle file you created above to select it, and then click OK to import your project.

What is EXT in build Gradle?

ext is shorthand for project. ext , and is used to define extra properties for the project object. (It's also possible to define extra properties for many other objects.) When reading an extra property, the ext. is omitted (e.g. println project. springVersion or println springVersion ).

What is zipTree in Gradle?

A FileTree represents a hierarchy of files. It extends FileCollection to add hierarchy query and manipulation methods. You typically use a FileTree to represent files to copy or the contents of an archive. You can obtain a FileTree instance using Project.


1 Answers

How about just:

def f = new File('the file path') if (!f.exists()) {     new URL('the url').withInputStream{ i -> f.withOutputStream{ it << i }} } 
like image 115
Ryan Stewart Avatar answered Sep 22 '22 02:09

Ryan Stewart