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

标签 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."/>

根据 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/

相关文章:

java - 部署后,Spring 不再找到 .Jar 之外的 JDBC.Properties

c++ - 相同的 'value' 对 std::set 意味着什么?

c# - 对象实例的比较,C#

python - Pandas /Python : Set value of one column based on value in another column

ant - 您可以在 Apache Ivy 中指定依赖项校验和吗?

java - 有没有办法在没有 ANT 的情况下仅在 .java 文件上运行 Checkstyle?

源文件丢失时 ant 复制任务挂起

string - Vba如何比较2列

使用自定义 php 代码的 drupal 条件操作

r - R中的条件和