How to read a json file into build.gradle and use the values the strings in build.gradle file

前端 未结 1 2042
隐瞒了意图╮
隐瞒了意图╮ 2021-02-14 05:12

for example, read the json file in build.gradle and use the json values as strings in the file

{
  \"type\":\"xyz\",
  \"properties\": {
    \"foo\"         


        
相关标签:
1条回答
  • From Gradle you can execute any Groovy code and Groovy already has build-in JSON parsers.

    E.g. you can use a task that will print your value into stdout:

    task parseJson {
        doLast {
            def jsonFile = file('path/to/json')
            def parsedJson = new groovy.json.JsonSlurper().parseText(jsonFile.text)
    
            println parsedJson.properties.bar.type
        }
    }
    
    0 讨论(0)
提交回复
热议问题