Mixing <ant> and <subant> leads to confusion…

By Robert. Filed in Java  |  
Tags:
TOP del.icio.us digg

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:\Temp\subanttest\sub\sub1>ant
Buildfile: build.xml

build:
[echo] sub1 base dir=C:\Temp\subanttest\sub\sub1

BUILD SUCCESSFUL
Total time: 0 seconds
C:\Temp\subanttest\sub\sub1>cd ..

C:\Temp\subanttest\sub>ant
Buildfile: build.xml

build:
[echo] sub base dir=C:\Temp\subanttest\sub

build:
[echo] sub1 base dir=C:\Temp\subanttest\sub\sub1

BUILD SUCCESSFUL
Total time: 1 second
C:\Temp\subanttest\sub>cd ..\main

C:\Temp\subanttest\main>ant
Buildfile: build.xml

build:
[echo] main base dir=C:\Temp\subanttest\main

build:
[echo] sub base dir=C:\Temp\subanttest\sub

build:
[echo] sub1 base dir=C:\Temp\subanttest\sub

BUILD SUCCESSFUL
Total time: 1 second
C:\Temp\subanttest\main>

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

Comments are closed.