我有一个 Ant 任务,它应该比较两个值的相等性。如果两个值不相等,我想失败:
<condition property="versionDoesNotMatch">
<not>
<equals arg1="applicationVersion" arg2="releaseNotesVersion"/>
</not>
</condition>
<fail if="versionDoesNotMatch" message="Version of Application and Release notes does not match."/>
根据 Ant 输出,两个值,releaseNotesVersion 和 applicationVersion 具有相同的值 1.7 但条件总是评估为真 - 这是因为 不是 将意味着,数字不相等。这让我想知道, Ant 是否会在比较这些值时遇到麻烦?
最佳答案
您在示例中匹配了两个文字字符串;这些永远不会相等,因此您的条件始终评估为真。假设您的 args 是 Ant 属性,您需要像这样评估属性值:
<condition property="versionDoesNotMatch">
<not>
<equals arg1="${applicationVersion}" arg2="${releaseNotesVersion}"/>
</not>
</condition>
<fail if="versionDoesNotMatch" message="Version of Application and Release notes does not match."/>
关于Ant:检查两个数字是否相等,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/10217124/