ant-dev mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From Paul Kilroy <paulkil...@yahoo.com>
Subject ant bug or user error?
Date Tue, 26 Mar 2002 16:40:12 GMT
I came across an issue with ant last week that I think
I've tracked down. Sorry if this is a known issue, I
scanned bugzilla and didn't find anything.

If I use the following build.xml:
<project name="test" default="foo">

    <target name="bug">
        <jar destfile="foo.jar">
            <fileset dir="." includes="*.class"/>
        </jar>
        <delete file="foo.jar"/>
    </target>

    <target name="moo" depends="bug"/>

    <target name="foo" depends="bug"/>

</project>

I get the following error when I run "ant foo moo":
BUILD FAILED
/home/pkilroy/antbug/build.xml:4: You must specify the
jar file to create!

I think the is related to the fact that ant caches
targets (and their tasks), but the task is "cleaned
up" at the end of the execute method. This pretty much
invalidates the cache for the target.

Solutions:
-Don't run targets twice -- User error. Could ant
catch this, so users know not to do it?
-Some how invalidate the cache of the task when that
cache chooses to clean itself up.
-Don't run the target again, it's already been run.
This is how I worked around the problem with the
following code. I'd rather see something like this
built into ant, but I'm pretty sure it won't work in
all situations:
<project name="test" default="foo">

    <target name="bug" unless="ran.jar">
        <jar destfile="foo.jar">
            <fileset dir="." includes="*.class"/>
        </jar>
        <delete file="foo.jar"/>
        <property name="ran.jar" value="true"/>
    </target>

    <target name="moo" depends="bug"/>

    <target name="foo" depends="bug"/>

</project>

Paul



__________________________________________________
Do You Yahoo!?
Yahoo! Movies - coverage of the 74th Academy Awards®
http://movies.yahoo.com/

--
To unsubscribe, e-mail:   <mailto:ant-dev-unsubscribe@jakarta.apache.org>
For additional commands, e-mail: <mailto:ant-dev-help@jakarta.apache.org>


Mime
View raw message