为了避免使用 antcall,您需要将条件放在每个子任务中。查看名称“skip.c”,可能是“除非”条件,如下所示:
<target name="test" depends="a,b,c" />
<target name="a" depends="a1,a2,a3" />
<target name="b" depends="b1,b2,b3" />
<target name="c" depends="c1,c2,c3" />
<target name="c1" unless="skip.c">
<!-- contents of target c1 -->
</target>
<target name="c2" unless="skip.c">
<!-- contents of target c2 -->
</target>
<target name="c3" unless="skip.c">
<!-- contents of target c3 -->
</target>
如果您需要在运行任务“c”时处理条件,您可以在目标“check_run_c”中执行此操作,如下所示:
<target name="test" depends="a,b,c" />
<target name="a" depends="a1,a2,a3" />
<target name="b" depends="b1,b2,b3" />
<target name="c" depends="check_run_c,c1,c2,c3" />
<target name="check_run_c">
<condition property="run.c">
<!-- set this property "run.c" if the "c*" targets should run... -->
<or>
<isset property="prop1"/>
<isset property="prop2"/>
</or>
</condition>
</target>
<target name="c1" if="run.c">
<!-- contents of target c1 -->
</target>
<target name="c2" if="run.c">
<!-- contents of target c2 -->
</target>
<target name="c3" if="run.c">
<!-- contents of target c3 -->
</target>
如果任务“c”中还有您只想有条件地运行的指令:
<target name="test" depends="a,b,c" />
<target name="a" depends="a1,a2,a3" />
<target name="b" depends="b1,b2,b3" />
<target name="c" depends="check_run_c,c1,c2,c3" if="run.c" >
<!-- contents of target c -->
</target>
<target name="check_run_c">
<condition property="run.c">
<!-- set this property "run.c" if the "c*" targets should run... -->
<or>
<isset property="prop1"/>
<isset property="prop2"/>
</or>
</condition>
</target>
<target name="c1" if="run.c">
<!-- contents of target c1 -->
</target>
<target name="c2" if="run.c">
<!-- contents of target c2 -->
</target>
<target name="c3" if="run.c">
<!-- contents of target c3 -->
</target>