2016-01-28 66 views
0

是否可以将文件从一个HTTP位置使用gradle这个任务是否可以使用gradle copy任务从url复制文件?

我想是这样的

task copyDatabaseFile(type: Copy) { 
    from 'http://somelocation/somedatabasefile.cdl'; 
    into 'target location' 
} 

副本,但是导致

Cannot convert URL 'http://server.cequint.com/cdldb/uscc/cityid.cdl' to a file. 

我已经无法找到任何类似事物的gradle示例

+0

你需要它是一个复制任务吗?因为不然的话,你总是可以使用一点点groovy来抓取一个在线文件 – RaGe

+0

我不确定它是否需要成为一个任务还没有,我还没有足够熟悉gradle知道。但该文件需要在实际构建开始之前被复制。 – Gruntcakes

回答

0

可以使用常规下载和从URL保存文件:

task downloadFile() << { 
    def address='url/to/download.ext' 
    def target='/path/tosave' 

    new File("${address.tokenize('/')[-1]}").withOutputStream { out -> 
     new URL(address).withInputStream { from -> out << from; } 
    } 
} 

如果需要此任务构建之前始终运行(只)任务运行,你可以添加到你的build.gradle:

build.dependsOn downloadFile

相关问题