Mixing and leads to confusion…

Update: It’s not a bug, it’s a feature! Seriously. 😉 It turns out that the <ant> task effectively sets the basedir property as a user-property, which means that it can’t be changed. User-properties are propogated through regardless of the inheritAll flag. The doco could have been clearer, but that’s life.

The easy work around: don’t use the dir attribute to locate the file, actually specify it in full (see the bug report for the example).

I lodged a bug report with Apache Ant today; first one in a long while. It turns out the the <ant> and <subant> tasks aren’t entirely compatible.

I’ve got three build files. The first uses <ant> to invoke the second. The second, in turn, uses <subant> to invoke a third (but potentially a heap) build file.

When I use either the third or the second build files directly, it works fine. When I get the first one to invoke it, the basedir for the third script is wrong (it’s set to the basedir of the second).

Example transcript:

C:Tempsubanttestsubsub1>ant
Buildfile: build.xml

build:
[echo] sub1 base dir=C:Tempsubanttestsubsub1

BUILD SUCCESSFUL
Total time: 0 seconds
C:Tempsubanttestsubsub1>cd ..

C:Tempsubanttestsub>ant
Buildfile: build.xml

build:
[echo] sub base dir=C:Tempsubanttestsub

build:
[echo] sub1 base dir=C:Tempsubanttestsubsub1

BUILD SUCCESSFUL
Total time: 1 second
C:Tempsubanttestsub>cd ..main

C:Tempsubanttestmain>ant
Buildfile: build.xml

build:
[echo] main base dir=C:Tempsubanttestmain

build:
[echo] sub base dir=C:Tempsubanttestsub

build:
[echo] sub1 base dir=C:Tempsubanttestsub

BUILD SUCCESSFUL
Total time: 1 second
C:Tempsubanttestmain>

There’s an example script in the bug report if anyone’s interested.

Author: Robert Watkins

My name is Robert Watkins. I am a software developer and have been for over 20 years now. I currently work for people, but my opinions here are in no way endorsed by them (which is cool; their opinions aren’t endorsed by me either). My main professional interests are in Java development, using Agile methods, with a historical focus on building web based applications. I’m also a Mac-fan and love my iPhone, which I’m currently learning how to code for. I live and work in Brisbane, Australia, but I grew up in the Northern Territory, and still find Brisbane too cold (after 22 years here). I’m married, with two children and one cat. My politics are socialist in tendency, my religious affiliation is atheist (aka “none of the above”), my attitude is condescending and my moral standing is lying down.

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )

Connecting to %s

%d bloggers like this: