Search code examples
javaantcopyfileset

Does Ant guarantee order of filesets?


in our project we use Ant to distribute files. There is hierarchy of files, and they overwrite files from previous level. Like this: default - level1 - level2. Currently it is made the way:

<copy todir="...">
 <fileset dir="${root}/default" includes="**/*" excludes="file1" />
 <fileset dir="${root}/level1" includes="**/*" />
 <fileset dir="${root}/level2" includes="**/*" excludes="file2"/>
</copy>

So we expected that all the folders contain file with the same name, it will be taken from level2 directory.

Not long ago we moved to a new build box with another version of Java and we discovered that the order of filesets is broken.

Is there a way to fix this issue without modifying ant config files? We have a big number of it. If there is no way, how can I got it off cheap? Thank you.


Solution

  • I don't know if the order of filesets is quaranteed, but the order of copy tasks is. So, following the suggestion of this answer, it might be a good idea to write several copy tasks with overwrite="true":

    <copy todir="...">
      <fileset dir="${root}/default" includes="**/*" excludes="file1" />
    </copy>
    <copy todir="...">
      <fileset dir="${root}/level1" includes="**/*" overwrite="true" />
    </copy>
    <copy todir="...">
      <fileset dir="${root}/level2" includes="**/*" excludes="file2" overwrite="true" />
    </copy>