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

8

我有一个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,但是该条件语句总是被判断为真 - 这意味着由于not,这两个数字不相等。这让我想知道,蚂蚁在比较这种类型的值时是否会有麻烦?
1个回答

20

你的示例中匹配了两个字面字符串,它们永远不会相等,因此你的条件始终评估为true。假设你的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."/>

网页内容由stack overflow 提供, 点击上面的
可以查看英文原文,
原文链接