如何在gradle中下载外部文件? [英] how to download external files in gradle?

查看:203
本文介绍了如何在gradle中下载外部文件?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个gradle项目,它需要使用http在互联网上的某个地方提供一些数据文件。目标是这个不可变的远程文件在第一次构建时被拉一次。



如何指示gradle将给定文件提取到本地目录?



我试过了

pre $ 任务获取(类型:Copy){
from'http://< myurl>'
转换为'data'
}

任务类型无法处理http。



额外问题:有没有办法像 wget -c 那样恢复以前中止/

$ b

 

解决方案

(f.exists()){
new URL('file-path')
如果(!f.exists()){
新的URL 'url')。withInputStream {i - > f.withOutputStream {it<< i}}
}


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?

解决方案

How about just:

def f = new File('the file path')
if (!f.exists()) {
    new URL('the url').withInputStream{ i -> f.withOutputStream{ it << i }}
}

这篇关于如何在gradle中下载外部文件?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆