For those of you that use Ant with multiple projects, where do you put the build.xml files? Do you put one in each project, or do you put them in a separate project that contains all your Ant-related files?
The usual recommendation is to put a build.xml in each project. But this has a few drawbacks:
-
It makes it hard to reuse common targets in multiple projects.
-
Sometimes you want to use Ant to export a project from source control and deploy it. Obviously you can’t do this if the build file is in the project itself.
But if you put them all in a common location:
-
People need to be aware of their location to use them; they can’t just use “ant -find” to find the current project’s file.
-
You can’t have different build instructions for different branches of the project.
What do you guys do?
EDIT: Thanks for the good suggestions so far. As far Maven, these aren’t Java projects, and I get the impression that Maven is only meant for Java.
Place the Ant files with the project. That is the de facto standard and recommended by the creator of Ant. I will try to address some of the issues you have brought up:
Reuse of common targets should be done using techniques as described by Eric Hatcher in his book Java Development with Ant. Basically, you extract all commonality into a some top level files that all other Ant files “inherit” from.
Using Ant to export a project from source control seems odd to me, but if you want to do this, use a different Ant file 🙂 You can make a target like
ant export -Dproject=foo/bar.For Ant, I recommend you grab that book – it has a ton of helpful techniques.
The real recommendation I would make though is to drop Ant and convert over to Maven – like the Apache Software Foundation did (they maintain both Ant and Maven).