Condition based antcall

This is what I am trying to achieve:

if the property is set, then call antcall target. is it doable? can someone tell me how?

<condition> <isset property="some.property"> <antcall target="do.something"> </isset> </condition> 
+7
source share
3 answers

Something like this should work:

 <if> <isset property="some.property"/> <then> <antcall target="do.something"/> </then> </if> 

If then the conditions require ant-contrib , then the same applies to anything useful in ant.

+8
source

I know that I am very late for this, but here is another way to do it if you use ant -contrib, where if does not support the nested antcall element (I use antcontrib 1.02b, which doesn’t work "t).

 <target name="TaskUnderRightCondition" if="some.property"> ... </target> 

You can extend this again to check if you need to set some.property just before this target is called, using the dependency depends on whether this is done before the if attribute is evaluated. So you can get the following:

 <target name="TestSomeValue"> <condition property="some.property"> <equals arg1="${someval}" arg2="${someOtherVal}" /> </condition> </target> <target name="TaskUnderRightCondition" if="some.property" depends="TestSomeValue"> ... </target> 

In this case, TestSomeValue is called, and if someval == someOtherVal, then some.property is set and, finally, TaskUnderRightCondition will be executed. If someval! = SomeOtherVal, then TaskUnderRightCondition will be skipped.

You can learn more about the conditions through the documentation .

+6
source

Also consider that you can call groovy for these purposes:

 <use-groovy/> <groovy> if (Boolean.valueOf(properties["some.property"])) { ant.project.executeTarget("do.something") } </groovy> 
-1
source

Source: https://habr.com/ru/post/919166/


All Articles