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?
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.
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.
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.
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>
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With