Breaking Version Inertia: Ant: import and macrodef
I've been using Ant since the very early days. ("Tomcat is built with Ant. What is Ant?" Remember those days?) Since my use of ant does not usually involve anything esoteric, I have fallen victim to version inertia. Ant 1.4, 1.5, 1.6, 1.7 came out over the years, and I didn't much glance at the release notes.
Meanwhile, some of my build.xml files has grown organically. Since the code is modularized with a nice "B depends on A, C depends on B, etc..." structure, the build.xml reflects that with targets like "compile-A", "compile-A-test", "run-A-test", "compile-B", "compile-B-test", "run-B-test", ..., each with their own classpath definition.
And as we added modules, we copy and pasted big chunks of Ant code, bloating the build file.
This become unbearable recently. And I looked for ways to make the build file manageable again. That's when I found the two new features of Ant: import and macrodef. Both are available in the latest Ant 1.7.0 release.
I won't bore you with the details of how these two tasks work. But it did allow me to break my build file into a
template-build.xmlwhich contains a set of macro definitions, and a bunch of
A-build.xml B-build.xml ...files each importing template-build.xml and instantiate the set of targets for a module. The build.xml then imports all the A-build.xml, ... files and use all the targets in a systematical way.
If you are using Ant, import and macrodef are your friends, just like if you are using C, #import and #define are your friends.
Re: Breaking Version Inertia: Ant: import and macrodef
Weiqi, have you tried Gant?
I don't have a lot of experience with either macrodef or Gant but I have often wondered if it (or its kind) is the future for builds.
As builds get increasingly complex, it seems to me that we want a real programming language. I suspect one day we will write unit tests for build elements (seriously). Not just reusable 3rd-party components but even for project-specific stuff.
Re: Breaking Version Inertia: Ant: import and macrodef
I've heard good things about Gant. But then again, I've heard good things about other tools: Maven, Rake, Ivy. So far, none of these satisfies the criteria I put out 683 days ago.
Maven comes closest to my ideal. But its XML syntax of the pom.xml files is still unnecessarily verbose. And its use of external repositories is sometimes undesirable.