When calling a task using <ant antfile="...">
, how do you get a property from within the <ant ...>
call? I ask because a Maven plugin -- the maven-antrun-plugin
-- uses this notation and states that using external files with this notation is recommended.
To see the code in a Maven project, click here: Retrieve value from external ant file for use in Maven project, or in an upstream bug report here.
Here's the ant code:
<project default="run-test">
<target name="run-test">
<!-- Call using antfile notation -->
<ant antfile="build.xml" target="antfile-task"/>
<echo level="info">Outside antfile: my.val: ${my.val}</echo>
</target>
<target name="antfile-task">
<property name="my.val" value="just some test value"/>
<echo level="info">Inside antfile: my.val: ${my.val}</echo>
</target>
</project>
Output:
Buildfile: build.xml
run-test:
antfile-task:
[echo] Inside antfile: my.val: just some test value
[echo] Outside antfile: my.val: ${my.val}