如何根据蚂蚁的OS改变变量

时间:2014-07-14 05:49:48

标签: ant

我正在使用多个目标来根据操作系统设置变量名称。

<target name="checkos">
  <condition property="isWindows">
    <os family="windows" />
  </condition>
  <condition property="isUnix">
    <os family="unix" />
  </condition>
</target> 

<target name="if_windows" depends="checkos" if="isWindows">
  <property name="path" location="deploy.exe"/>
</target>

<target name="if_unix" depends="checkos" if="isUnix">
  <property name="path" location="deploy.sh"/>  
</target>

如何在单个目标中设置它。 我使用if和condition但它不允许它这样做。

1 个答案:

答案 0 :(得分:0)

使用ant&gt; = 1.9.1使用new if/unless feature introduced with Ant 1.9.1但是你应该使用Ant 1.9.3,因为Ant 1.9.1中存在错误see this answer for details

<project 
  xmlns:if="ant:if"
  xmlns:unless="ant:unless"
>

<target name="setos">
 <condition property="isWindows">
  <os family="windows" />
 </condition>
 <property name="path" location="deploy.exe" if:true="${isWindows}"/>
 <property name="path" location="deploy.sh" unless:true="${isWindows}"/>
</target>

</project>

否则与ant&lt; 1.9.1使用类似的东西:

<target name="checkos">
 <condition property="isWindows">
  <os family="windows" />
 </condition>
</target> 

<target name="if_windows" depends="checkos" if="isWindows">
 <property name="path" location="deploy.exe"/>
</target>

<target name="if_unix" depends="checkos" unless="isWindows">
 <property name="path" location="deploy.sh"/>  
</target>