小编cry*_*ity的帖子

Gradle:将变量从一个任务传递到另一个任务

我想在同一个build.gradle文件中将变量从一个任务传递到另一个任务.我的第一个gradle任务拉出最后一个提交消息,我需要将此消息传递给另一个任务.代码如下.提前感谢您的帮助.

task gitMsg(type:Exec){
    commandLine 'git', 'log', '-1', '--oneline'
    standardOutput = new ByteArrayOutputStream()
    doLast {
       String output = standardOutput.toString()
    }
}
Run Code Online (Sandbox Code Playgroud)

我想将变量'output'传递给下面的任务.

task notifyTaskUpcoming << {
    def to = System.getProperty("to")
    def subj = System.getProperty('subj') 
    def body = "Hello... "
    sendmail(to, subj, body)
}
Run Code Online (Sandbox Code Playgroud)

我想将git消息合并到'body'中.

git variables groovy task gradle

22
推荐指数
2
解决办法
2万
查看次数

Groovy&json:如何从json获取数组的长度?

我使用curl获取一些数据,然后用它解析它JsonSlurper.数据结构是

"results" : [ 
   {
      "uri" : "http://localhost:8081/artifactory/api/storage/...",
      "created" : "2015-11-27"
   },
   {
      "uri" : "http://localhost:8081/artifactory/api/storage/...",
      "created" : "2015-11-27"
   }, 
   {
      "uri" : "http://localhost:8081/artifactory/api/storage/...",
      "created" : "2015-11-30"
   } 
]
Run Code Online (Sandbox Code Playgroud)

所以,如果我没有弄错的话,整个事物都被认为是一个对象.但是对象(结果)中有一个数组,其中包含该数组中的对象.

我需要得到结果数组的长度.当我尝试做json.result.length时,我收到一个null.

如何获得results阵列的长度?

def list = ['curl', '-u', 'user:pass',     "http://localhost:8081/..."].execute()
def json = new JsonSlurper().parseText(list.text)
println json.result.size()
Run Code Online (Sandbox Code Playgroud)

arrays groovy json

1
推荐指数
1
解决办法
2万
查看次数

标签 统计

groovy ×2

arrays ×1

git ×1

gradle ×1

json ×1

task ×1

variables ×1