Ant构建中不完整参数的异常处理

问题描述 投票:0回答:2

正确的一个:ant verifyParameters -DrestoreValue=false

例如:ant verifyParameters -Drestoreval=false

如果参数拼写错误,我想抛出一个错误,即使我传递了多个参数,它也应该抓住所有参数并抛出一个错误。

java ant
2个回答
1
投票
但是您可以检查,是否设置了正确的参数,如果缺少该参数,则失败。

这里是一个例子。如果未设置参数default,则主要目标check-parameter被依赖目标restoreValue屏蔽,该目标将失败。

<project name="option-test" default="default"> <!-- This is the main target. It depends on target check-parameter which fails, if parameter restoreValue is not set. --> <target name="default" depends="check-parameter"> <echo message="Start build ..." /> <echo message="restoreValue = ${restoreValue}" /> </target> <!-- This helper target sets property parameterok to true, if restoreValue is set. And to false, otherwise. --> <target name="check-is-set"> <condition property="parameterok"> <isset property="restoreValue"/> </condition> </target> <!-- This target depends on target check-is-set, which calculates the parameterok property. The unless attribute evaluates the parameterok property, so that the target body is only excuted, if paramterok=false. So the build fails only if parameter restoreValue is not set. --> <target name="check-parameter" unless="${parameterok}" depends="check-is-set"> <fail message="Parameter restoreValue not set!" /> </target>


0
投票
© www.soinside.com 2019 - 2024. All rights reserved.