0

I am using more then one target for setting the variable name depending on OS.

<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>

How can i set it in the single target. I used if and condition but it doesn't allow it to do so.

jasmeet
  • 31
  • 4

1 Answers1

0

With ant >= 1.9.1 use the new if/unless feature introduced with Ant 1.9.1 but you should use Ant 1.9.3 because of bugs in 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>

otherwise with ant < 1.9.1 use something like :

<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>
Community
  • 1
  • 1
Rebse
  • 10,307
  • 2
  • 38
  • 66
  • I am using ant 1.9.4. but it is giving me error with if condition. Error is 'The prefix "if" for attribute "if:true" associated with an element type " property" is not bound. – jasmeet Jul 14 '14 at 09:36
  • Oh i got the solution. We need to use this to use if unless. – jasmeet Jul 14 '14 at 09:46
  • Sorry - forgot about that in my snippet - only linked to the ant manual. New edit now contains the namespace declarations. – Rebse Jul 14 '14 at 10:31