2015-09-02 18 views
2

我正在写一个gradle任务。它调用的任务返回3,表示成功运行,而不是3.我该如何去做这件事?gradle执行块不应该失败,因为非零输出在

task copyToBuildShare(){ 
    def robocopySourceDir = "build\\outputs\\apk" 
    def cmd = "robocopy "+ robocopySourceDir + " C:\\TEST *.* /MIR /R:5 2>&1" 
    exec { 
     ignoreExitValue = true 
     workingDir '.' 
     commandLine "cmd", "/c", cmd 
     if (execResult.exitValue == 3) { 
     println("It probably succeeded") 
     } 
    } 
} 

它给人的错误:

Could not find property 'execResult' on task

我不想创建一个单独的任务。我希望它在exec块中。我究竟做错了什么?

+1

常见错误:不包括 “ignoreExitValue =真” 之间的等号(=)。它应该是 “ignoreExitValue true” – javajon

回答

2

您将需要指定该任务是Exec类型。这是通过指定任务类型,像这样

task testExec(type: Exec) { 

} 

在特定情况下完成的,你还需要确保你不要试图让execResult直到EXEC已完成通过包装可以做到这一点在doLast中进行检查。

task testExec(type: Exec) { 
    doLast { 
     if (execResult.exitValue == 3) { 
      println("It probably succeeded") 

     } 
    } 
} 

这里的执行ls和检查它的返回值

task printDirectoryContents(type: Exec) { 

    workingDir '.' 
    commandLine "sh", "-c", "ls" 

    doLast{ 
     if (execResult.exitValue == 0) { 
      println("It probably succeeded") 

     } 
    } 
} 
相关问题