Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
523 views
in Technique[技术] by (71.8m points)

how to download external files in 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?

See Question&Answers more detail:os

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Answer

0 votes
by (71.8m points)

How about just:

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

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

2.1m questions

2.1m answers

60 comments

56.8k users

...