Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

can you do this seemingly simple Ant copy task without using ant-contrib's foreach?

Tags:

copy

wildcard

ant

I have a source directory with a bunch of plugins. Each plugin has its own lib directory. I want the contents of each of those lib directories to be merged into a single lib directory within my build. In theory you'd do something like this:

<copy todir="build/web/lib">
    <fileset dir="web/plugins/*/lib/" includes="**/*" />
</copy>

However, Ant chokes when the dir attribute includes a wildcard. Is ant-contrib the only alternative, or can you make this work with vanilla ant?

Choke message is build.xml:28: [...]/web/plugins/*/lib does not exist.

like image 428
Jeoff Wilks Avatar asked Dec 05 '25 22:12

Jeoff Wilks


1 Answers

The dir= attribute of a fileset doesn't take a wildcard - hence the error you see. You need to specify a single directory, in this case web/plugins, and use a slightly different wildcard for the includes:

<copy todir="build/web/lib">
    <fileset dir="web/plugins" includes="*/lib/**/*" />
</copy>

If you need to alter the paths as you copy, you can use a mapper, for example the flattenmapper will give you file names with all leading directory information stripped off.

like image 118
martin clayton Avatar answered Dec 10 '25 00:12

martin clayton



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!