How to parameterize a path in ANT?
Posted
by strelokstrelok
on Stack Overflow
See other posts from Stack Overflow
or by strelokstrelok
Published on 2010-03-24T04:10:33Z
Indexed on
2010/03/24
4:13 UTC
Read the original article
Hit count: 327
I have the following defined in a file called build-dependencies.xml
<?xml version="1.0" encoding="UTF-8"?>
<project name="build-dependencies">
...
<path id="common-jars">
<fileset file="artifacts/project-1/jar/some*.jar" />
<fileset file="artifacts/project-2/jar/someother*.jar" />
</path>
...
</project>
I include it at the top of my build.xml file. Now I need to make the artifacts folder a parameter so it can be changed during execution of different targets. Having this...
<?xml version="1.0" encoding="UTF-8"?>
<project name="build-dependencies">
...
<path id="common-jars">
<fileset file="${artifacts}/project-1/jar/some*.jar" />
<fileset file="${artifacts}/project-2/jar/someother*.jar" />
</path>
...
</project>
...and defining an "artifacts" property (and changing it) in the target does not work because it seems that the property substitution happens when the path is defined in build-dependencies.xml
How can I solve this? One way I was thinking was to have a parameterized macro and call that before the path is actually used, but that seems not elegant. Something like this:
<macrodef name="create-common-jars">
<attribute name="artifacts"/>
<sequential>
<path id="common-jars">
<fileset file="@{artifacts}/project-1/jar/some*.jar" />
<fileset file="@{artifacts}/project-2/jar/someother*.jar" />
</path>
</sequential>
</macrodef>
© Stack Overflow or respective owner