wood burning stoves 2.0*
The moose likes Other Open Source Projects and the fly likes hierarchical ant scripts Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Products » Other Open Source Projects
Bookmark "hierarchical ant scripts" Watch "hierarchical ant scripts" New topic
Author

hierarchical ant scripts

George Brown
Ranch Hand

Joined: Sep 26, 2000
Posts: 919
Many moons ago a way of dealing with large and sprawling projects using make was to split up the project into many smaller parts and use a set of make rules that lent themselves to a hierarchical structure of Makefiles.
Now I'm using and and getting to the stage with it that the projects are getting larger and larger and all the rules for building are stuck into a single build.xml file that is getting a bit too large.
What I would like to do would be to use a hierarchical structure of build.xml files, which relied upon a single set of rules. But ant doesn't seem to work like that. Has anyone tackled this problem before and found a satisfactory solution to it?
Thomas Paul
mister krabs
Ranch Hand

Joined: May 05, 2000
Posts: 13974
I'm moving this to Jakarta Projects.


Associate Instructor - Hofstra University
Amazon Top 750 reviewer - Blog - Unresolved References - Book Review Blog
Karthik Guru
Ranch Hand

Joined: Mar 06, 2001
Posts: 1209
U can do that.
Say you have separate build files for different modules (for eg: "build-module2.xml","build-module3.xml")
You can call it form within a main build file like this:
<target name="hello">
<ant antfile= "build-module2.xml"/>
</target>
<target name="hello">
<ant antfile= "build-module3.xml"/>
</target>
..
[/CODE]
HTH
Tim Holloway
Saloon Keeper

Joined: Jun 25, 2001
Posts: 16305
    
  21

Ant was, in fact, designed with things like that in mind. If you look close at the docs, you'll notice that in certain cases, Ant will even look "uphill" for build instructions.
In practical terms, I'm using both the <ant;> and <antcall> features to assist me in building and maintaining complex websites daily.


Customer surveys are for companies who didn't pay proper attention to begin with.
George Brown
Ranch Hand

Joined: Sep 26, 2000
Posts: 919
If that's the case maybe I should look at this again. Let me explain what I was looking at doing...
What I wanted to do was to build a hierarchical set of build.xml files. The root build.xml file would define a set of tasks which the leaf build.xml files would rely upon, in the sense that they could directly call the tasks defined at the root using the <antcall> task.
Tim, is that the kind of thing that you are doing? It seems to me that if it's not possible it would lead to an awful lot of duplication when the leaf build.xml file tasks have a lot in common. As you say, in certain cases, Ant will even look "uphill" for build instructions. Which cases are those?
I'll clarify the sort of thing that I wanted to do ...
build.xml

other.xml

Both default targets are called, but when I try to call back to the original file, to the xyz target, it complains of not finding the target within the current project. Can I use multiple files within the same project or am i forced to use multiple projects?
Tim Holloway
Saloon Keeper

Joined: Jun 25, 2001
Posts: 16305
    
  21

Here's the official from the Ant 1.5 docs on "uphill" searches:

These files DO have a lot of duplication, in part because they're automatically generated, but it's supposed to be possible to make subproject code that would look something like this:

Refer to the <ant> task's docs for info on what gets used as the reference directory for relative paths.
I'd probably put sub-tasks in alternative buildfiles rather than in the main build.xml, but it would depend on the overall shape of the project and how wierd I was the day I laid it all out.
[ September 27, 2002: Message edited by: Tim Holloway ]
David Weitzman
Ranch Hand

Joined: Jul 27, 2001
Posts: 1365
This doesn't really address the issues at hand, but XML external entities are widely underused. You can avoid some code duplication with strategic use of them.
Tim Holloway
Saloon Keeper

Joined: Jun 25, 2001
Posts: 16305
    
  21

Curious. It appears my quote out of the Ant docs didn't appear!
Frank Carver
Sheriff

Joined: Jan 07, 1999
Posts: 6920
Does "Configure" on this page sound like what you want ?


Read about me at frankcarver.me ~ Raspberry Alpha Omega ~ Frank's Punchbarrel Blog
George Brown
Ranch Hand

Joined: Sep 26, 2000
Posts: 919
Thanks for all replies, I shall certainly make use of those tips and tricks when I split out my increasingly unwieldy single ant build.xml file.
Does "Configure" on this page sound like what you want ?
yes, thanks Frank, looks like just the thing I'm looking for. Not sure about the only 'compatible with ant 1.2 or 1.3' bit as I'm using the 1.5 version at the moment but I'll certainly try it, and maybe I can adapt it.
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: hierarchical ant scripts