Java – extends existing ant path Tags

Can existing path markers in ant build files be extended? For example, I want to expand:

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

Use new path = module / lib The result is equivalent to:

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

Solution

If you try this method, you cannot extend the existing path directly:

<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 because you are trying to read and set the "circle" of the path at the same time

You can break the circle by adding additional steps to achieve the effect you want Store the current value in the < string > resource before setting the path each time:

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

The runtime produces something like this:

[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 reassign the ID to a different path each time Usually this is a bad idea because you cannot determine the path to use for each point in the build: so use it carefully

The content of this article comes from the network collection of netizens. It is used as a learning reference. The copyright belongs to the original author.
THE END
分享
二维码
< <上一篇
下一篇>>