ant-dev mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From Jesse Glick <jesse.gl...@sun.com>
Subject Re: [PATCH] basedir for child project not set correctly from <ant> task
Date Sat, 20 Oct 2001 09:46:19 GMT
I ran into the same problem myself some time ago; apparently it is
"as-designed" though for some people it is counterintuitive.

- if you pass dir="...", that is the basedir you will get; this is documented
in the <ant/> page, though it should be emphasized there that the subproject's
basedir attr is ignored

- (note that the default script is then ${thatdir}/build.xml--docs say default
is "build.xml" but do not clarify that this is relative to the passed-in dir)

- if you pass antfile="...", you can specify e.g. "zotdir/build.xml" but then
the basedir is inherited from the current project (!)

- you can pass both if you want

As far as I can tell, there is no way to do the thing which I at least would
95% of the time want to do: run a specific build script and ask Ant to give it
the basedir it specifies for itself (without hardcoding this into the calling
script).

All the scripts I would write assume they know where files are. E.g.:

/sourcetree/build.xml
/sourcetree/src/Foo.java
/sourcetree/result.jar
/sourcetree/mf.txt

<project default="jar" basedir=".">
    <target name="compile">
        <javac srcdir="src" destdir="src"/>
    </target>
    <target name="jar" depends="compile">
        <jar jarfile="result.jar" basedir="src" manifest="mf.txt"/>
    </target>
</project>

In such a script, the basedir should never be set to anything other than
/sourcetree (directory containing build.xml), or the script will not work. You
might of course wish to duplicate the source tree, but then you would be
copying the script too. In this scenario, changing the basedir externally is
not only useless but dangerous.

For this reason I always use basedir="." on every script, and when using
<ant/> always pass just dir="something" (i.e. by convention force every
basedir to be the same as the script's containing directory). This works, i.e.
calling <ant/> works similarly to running ant on the command line, though you
do not have the option of using a more convenient basedir.

-Jesse

David Sitsky wrote:
> [snip]
> <project name="tester" default="zot" basedir=".">
>     <target name="zot">
>          <ant dir="${basedir}/zotdir" target="jar"/>
>     </target>
> </project>
> [snip]
> If in the ~/TEST directory I call "ant", I would have expected the echo to
> have printed ~/TEST, but it prints ~/TEST/zotdir, regardless of the setting
> of basedir in ~/TEST/zotdir/build.xml.
> 
> However, if I do:
> 
> cd ~/TEST/zotdir
> ant
> 
> then the echo message prints out the correct result.

-- 
Jesse Glick        <mailto:jesse.glick@sun.com>
NetBeans, Open APIs  <http://www.netbeans.org/>

Mime
View raw message