如何在嵌套的Groovy脚本中检测Ant构建错误

时间:2014-08-22 20:11:36

标签: ant groovy

我有一个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目标是否失败?

1 个答案:

答案 0 :(得分:0)

经过一些实验,我发现你可以用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>