Multiple condition checking in ANT targets

If you need multiple condition checking in ANT to control the build process to go or not to go. You can follow this example.

<target name="check_1" depends="">
    <available file="abc/def/target_1.js" property="target_1.present"/>
    <fail unless="target_1.present" message="check_1 failed"/>

<target name="check_2" depends="check_1" if="target_1.present">
    <available file="abc/def/target_2.js" property="target_2.present"/>
    <fail unless="target_2.present" message="check_2 failed"/>

<target name="check_3" depends="check_2" if="target_2.present">
    <available file="abc/def/target_3.js" property="target_3.present"/>
    <fail unless="target_3.present" message="check_3 failed"/>
  1. If we execute this ANT job on check_3 target, check_3 depends on target check_2. Target check_2 depends on target check_1. Firstly, target check_1 will be executed. Then target check_2 and target check_3.
  2. In each target, we define a “available” task and check file existence and store the result in target_1.present, target_2.present, target_3.present.
  3. Target check_2 has a “if” parameter checking the value of target_1.present. Target check_2 can only be executed when target_1.present is true.
  4. Therefore, target check_3 can only be executed when target check_1 and check_2 are executed plus values of target_1.present and target_2.present are both true.


Leave a Reply

Your email address will not be published.