dateboyTom
dateboyTom

Reputation: 109

how to pass parameters to ant task's depends field

I have a build.xml that should receive dynamically parameters to the depends field. I define this parameter in some other app.xml such as:

ops=op1, op2, op3,op4,op5,.... opn

then I import this app.xml into build.xml and want to use the parameter ops there.

<project name="Project" basedir="." default="help">
    <target name="test" depends="{$ops}" description="executea series of commands in ant">
      <echo message="batch operation job done.  tasks = {$ops}"/>
    </target>
</project>

How can I pass a parameter from one ant file to another?

Upvotes: 1

Views: 3853

Answers (2)

Mensfeld
Mensfeld

Reputation: 101

As already mentioned, you can't put properties into the Depends field. However, if you are setting a property, you can use it in the If field. Example

<project name="appProject">

  <target name="test" depends="target1,target2,target3" description="execute series of commands"/>

  <target name="target1" if="do.target1">
    <echo message="Target1 executed." />
  </target>

  <target name="target2" if="do.target2">
    <echo message="Target2 executed." />
  </target>

  <target name="target3" if="do.target3">
    <echo message="Target3 executed." />
  </target>

</project>

Then you set in your build.xml the given target flag do.target1, do.target2 or do.target3 and it gets executed. Basically what you wanted to have. In the If field properties are only checked for value. Also, you don't have to use the ${ } construction for the properties.

Upvotes: 0

David W.
David W.

Reputation: 107090

The depends parameter does not take properties.

Ant uses a dependency matrix to determine what should be built and in what order. This matrix is calculated before any part of the build file itself is executed, so properties aren't even set when this is done.

What are you trying to accomplish? Maybe if we have a better idea what you want, we can help you with it. Ant isn't a scripting language like BASH or Python.

Upvotes: 2

Related Questions