Search code examples
androidgradlebuild.gradlegradle-kotlin-dsl

How can I execute curl in gradle and write a output file on specific directory?


Here is the code curl to download file in github private repo

def command = "curl -s -O https://[email protected]/myGitHubAccount/myrepo/master/app/src/main/res/values/colors.xml"
task myCurlTask(){
command.execute()

When I execute it the output file place in my root project directory. I want to execute it and put the file in my res/values folder of my android project.

How can I do that? And How to write that code in gradle.kts?


Solution

  • Finally I found

    tasks.register("downloadColorsFromPrivateRepo") {
    val destinationPath = "${project.projectDir}/src/main/res/values/colors.xml"
    val githubPrivateRepoToken = "myToken"
    val command = "curl -o $destinationPath https://${githubPrivateRepoToken}@raw.githubusercontent.com/myGitHubAccount/myrepo/master/app/src/main/res/values/colors.xml"
    Runtime.getRuntime().exec(command)
    

    }