如何在错误的蚂蚁目标上显示更多信息性错误消息?

时间:2011-01-17 20:32:30

标签: ant

当我们的某个开发人员错误输入无法识别的ant目标名称时,结果是一条不友好的错误消息,例如:

BUILD FAILED
Target "foo" does not exist in the project "bar". 

我更喜欢的是它运行一个显示可用目标列表的目标。有没有办法捕获蚂蚁错误消息,而是运行另一个目标,或某种自定义错误消息?

感谢。

3 个答案:

答案 0 :(得分:2)

错误消息非常用户友好。它明确指出build.xml文件中不存在指定的目标。也许非技术用户会因为简短的错误消息而烦恼。 (什么是目标?什么是项目“栏”?)但是,程序员应该具备足够的技术来阅读信息并实现他们的错误。

开发人员可以通过ant --projecthelp命令显示所有外部目标。这可以缩写为ant -p

您可以通过将description参数添加到开发人员可以使用的有效目标来帮助完成此过程。如果build.xml中的单个目标具有description参数,ant --projecthelp将只显示带有description参数的目标。

您还可以在<description>文件的顶部添加build.xml任务,以显示有关项目的信息。这是一个简单的例子:

<project name="Fubar" default="foo">

    <description>
        Project Fubar is a highly secret project that you shouldn't know
        anything about. If you have read this, you've violated national
        security guidelines and must be terminated with extreme finality.
        Hey, it hurts me more than  it hurts you.
    </description>

    <target name="foo"
        description="Runs target &quot;foo&quot;"/>

    <target name="fu"/>     <!-- Internal target No description -->

    <target name="bar"
        description="Runs target &quot;bar&quot;"/>
</project>

这是我的ant -p输出:

$ ant --projecthelp
Buildfile: build.xml

        Project Fubar is a highly secret project that you shouldn't know
        anything about. If you have read this, you've violated national
        security guidelines and must be terminated with extreme finality.
        Hey, it hurts me more than  it hurts you.

Main targets:

 bar  Runs target "bar"
 foo  Runs target "foo"
Default target: foo
$

注意我的build.xml中有三个目标,但未提及目标fu,因为它只是一个内部目标。

答案 1 :(得分:1)

  1. 在这种情况下,Ant-contrib的Trycatch任务可能很有用
  2. 自定义{API}的Listener

答案 2 :(得分:0)

ant -p会在build.xml文件中显示目标列表。这够好吗?

相关问题