Extend an existing ant path tag

Is it possible to extend an existing path tag in an ant build file? For example, I want to expand:

<path id="project.classpath">
  <pathelement path="build/classes" />
</path>

with a new one path=module/lib. So that the result is equivalent:

<path id="project.classpath">
  <pathelement path="build/classes" />
  <pathelement path="module/lib" />
</path>
+4
source share
1 answer

You cannot directly distribute the existing path 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 roundness when you try to read 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 path setting, save the current value in the resource <string>:

<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}" />

Installs something like this at startup:

[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

id . , , : .

0

All Articles