Reputation: 867
Is it possible to extend an existing path tag in a ant build file? E.g I want to extend:
<path id="project.classpath">
<pathelement path="build/classes" />
</path>
with a new path=module/lib
. So that the result is equivalent to:
<path id="project.classpath">
<pathelement path="build/classes" />
<pathelement path="module/lib" />
</path>
Upvotes: 4
Views: 458
Reputation: 78225
You can't extend an existing path directly, if you try something like this:
<path id="project.classpath">
<pathelement path="build/classes" />
</path>
<path id="project.classpath">
<pathelement path="${ant.refid:project.classpath}" />
<pathelement path="module1/lib" />
</path>
It will fail due to a "circularity" where you're trying to read from and set the path at the same time.
You can do what you want by adding an extra step to break the circle. Before each setting of the path, store the current value in a <string>
resource:
<path id="cp">
<pathelement path="build/classes" />
</path>
<echo message="${ant.refid:cp}" />
<string id="cps" value="${toString:cp}" />
<path id="cp">
<pathelement path="${ant.refid:cps}" />
<pathelement path="module1/lib" />
</path>
<echo message="${ant.refid:cp}" />
<string id="cps" value="${toString:cp}" />
<path id="cp">
<pathelement path="${ant.refid:cps}" />
<pathelement path="module2/lib" />
</path>
<echo message="${ant.refid:cp}" />
Yields something like this when run:
[echo] /ant/path/build/classes
[echo] /ant/path/build/classes:/ant/path/module1/lib
[echo] /ant/path/build/classes:/ant/path/module1/lib:/ant/path/module2/lib
You are re-assigning the id
to a different path each time. Normally this is a bad idea as you can't be sure what path was used at each point in the build: so use with care.
Upvotes: 1