Ant:检查两个数字是否相等

时间:2012-04-18 20:04:33

标签: ant comparison conditional

我有一个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."/>

根据蚂蚁输出,两个值,releaseNotesVersion和applicationVersion具有相同的值 1.7 ,但条件总是计算为true - 由于意味着,数字不相等。这让我想知道,如果蚂蚁比较那些价值观会有麻烦吗?

1 个答案:

答案 0 :(得分:15)

您在示例中匹配两个文字字符串;这些永远不会是平等的,所以你的条件总是评估为真。假设你的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."/>