Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Set a property inside one ant target and use it in another target

Tags:

ant

My build file is

<target name="default">  
 <antcall target="child_target"/>  
 <echo> ${prop1}   </echo>  
</target>

<target name="child_target">  
 <property name="prop1" value="val1"/>   
</target>

I get an error that ${prop1} has not been set. How do I set a property in the target?

like image 901
Anuja Chinchwadkar Avatar asked Dec 27 '10 18:12

Anuja Chinchwadkar


People also ask

How do I run a specific target in Ant?

To run the ant build file, open up command prompt and navigate to the folder, where the build. xml resides, and then type ant info. You could also type ant instead. Both will work,because info is the default target in the build file.

How do I override property value in Ant?

Ant Properties are set once and then can never be overridden. That's why setting any property on the command line via a -Dproperty=value will always override anything you've set in the file; the property is set and then nothing can override it. This way: Anything set at the command line takes precedence over build.

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.


1 Answers

antcall creates a new project. From the Ant documentation:

The called target(s) are run in a new project; be aware that this means properties, references, etc. set by called targets will not persist back to the calling project.

Use depends instead:

<project default="default">
  <target name="default" depends="child_target">
    <echo>${prop1}</echo>
  </target>
  <target name="child_target">
    <property name="prop1" value="val1"/>
  </target>
</project>
like image 200
Brett Kail Avatar answered Sep 29 '22 18:09

Brett Kail