Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Antcall: Call nested ant target from another file

Tags:

file

ant

antcall

I have two ant files:

1) Main file

<include file="otherFile.xml" as="otherFile"/>

<target name="firstTarget">
    <antcall target="otherFile.secondTarget"/>
</target>

2) Utilities file

<target name="secondTarget">
    <antcall target="thirdTarget"/>
</target>

<target name="thirdTarget">
     <echo message="ok"/> 
</target>

When I invoke the firstTarget it says it cannot find the thirdTarget. If I change the secondTarget this way:

<target name="secondTarget">
    <antcall target="otherFile.thirdTarget"/>
</target>

then it works. But then I cannot use secondTarget directly. Because the second file does not knwon the prefix otherFile

like image 996
user1518048 Avatar asked Jul 12 '13 13:07

user1518048


People also ask

What is Antcall target?

When a target is invoked by antcall , all of its dependent targets will also be called within the context of any new parameters. For example. if the target doSomethingElse ; depended on the target init , then the antcall of doSomethingElse will call init during the call.

What is an Ant task?

Ant tasks are the units of your Ant build script that actually execute the build operations for your project. Ant tasks are usually embedded inside Ant targets. Thus, when you tell Ant to run a specific target it runs all Ant tasks nested inside that target.


2 Answers

You may try:

<ant antfile="otherFile.xml" target="secondTarget"/>

And no need to include the otherFile.

like image 183
user5088115 Avatar answered Oct 01 '22 17:10

user5088115


Use the following pattern in any file that will be both directly invoked and included:

<project name="my-project">
  <!-- if this is the top-level build.xml, ${self} == "" -->
  <condition property="self" value="">
    <equals arg1="${ant.project.name}" arg2="my-project" />
  </condition>
  <!-- if this is an included build.xml, ${self} == "my-project." -->
  <property name="self" value="my-project." /><!-- note the trailing dot -->
  ...

Then use the following for the antcall:

<antcall target="${self}target" />
like image 41
Jay Dunning Avatar answered Oct 01 '22 16:10

Jay Dunning