当我们的一位开发人员错误输入无法识别的 ant 目标名称时,结果是一条不友好的错误消息,例如:
BUILD FAILED
Target "foo" does not exist in the project "bar".
我更喜欢它运行一个显示可用目标列表的目标。有没有办法捕获 ant 错误消息并运行另一个目标或某种自定义错误消息?
谢谢。
最佳答案
错误消息非常用户友好。它明确指出指定的目标不存在于 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 "foo""/>
<target name="fu"/> <!-- Internal target No description -->
<target name="bar"
description="Runs target "bar""/>
</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
未提及,因为它只是一个内部目标。
关于ant - 如何在错误键入的 ant 目标上显示信息更丰富的错误消息?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/4717583/