how to download external files in gradle?

前端 未结 7 503
你的背包
你的背包 2020-12-02 09:50

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

相关标签:
7条回答
  • 2020-12-02 10:41

    Kotlin Version of @Benjamin's Answer

    buildscript {
        repositories {
            jcenter()
            google()
        }
    
        dependencies {
            classpath("com.android.tools.build:gradle:4.0.1")
        }
    }
    
    tasks.register("downloadPdf"){
        val path = "myfile.pdf"
        val sourceUrl = "https://file-examples-com.github.io/uploads/2017/10/file-sample_150kB.pdf"
        download(sourceUrl,path)
    }
    
    fun download(url : String, path : String){
        val destFile = File(path)
        ant.invokeMethod("get", mapOf("src" to url, "dest" to destFile))
    }
    
    0 讨论(0)
提交回复
热议问题