我有一个build.xml,其中包含以下内容:
<project name="myProject>
<target name="execGroovy">
<groovy>
def task = project.createTask('antcall')
task.target = "taskTarget"
task.perform()
</groovy>
</target>
<target name="taskTarget">
<!-- do some things here -->
</target>
</project>
如果perform()
调用失败,脚本似乎会无声地崩溃。如何防止这种情况和/或检测从Groovy脚本调用的Ant目标是否失败?
经过一些实验,我发现可以用try catch finally块包围groovy命令,如下所示:
<project name="myProject>
<target name="execGroovy">
<groovy>
def task = project.createTask('antcall')
task.target = "taskTarget"
try {
task.perform()
} catch(Exception e) {
// do something appropriate
}
</groovy>
</target>
<target name="taskTarget">
<!-- do some things here -->
</target>
</project>