Yesterday I lost 1 hour to fix an antlib namespace issue.  I have no found
how to fix it, but I still don't clearly understand what is actually wrong
(=what error message should ant report).

I have an antlib defined in an XML file like this :

<antlib xmlns:deco="antlib:net.sourceforge.deco.ant">
  <taskdef name="analyze"
           classname="net.sourceforge.deco.ant.Analyze"
    />
</antlib>


And I have my project was using it like this :

<project name="build_base" xmlns:deco="net.sourceforge.deco.ant">

        <typedef resource="net/sourceforge/deco/ant/antlib.xml"
uri="net.sourceforge.deco.ant">
            <classpath>
                <fileset dir="${build.script.dir}/lib/">
                    <include name="deco*.jar"/>
                  </fileset>
                  <pathelement
location="${build.script.dir}/lib/asm-3.1.jar" />
            </classpath>
          </typedef>

</project>


This was working fine, and I could use <deco:analyse> task in my build.

But then I added a presetdef in my anlib that refined analyze like this
(simplified version):

<antlib xmlns:deco="antlib:net.sourceforge.deco.ant">
  <taskdef name="analyze"
           classname="net.sourceforge.deco.ant.Analyze"
    />
  <presetdef name="check-compile">
          <deco:analyze type="COMPILE">
              <deco:check-compile-report/>
          </deco:analyze>
  </presetdef>

</antlib>

This was failing because deco:analyze was not found when presetdef
executed.
I tried unsuccesfully to change the usage of the namespace in different way,
then I plugged a debugger and I found that the analyze task did exist, but
with the name net.sourceforge.deco.ant:analyze while
antlib:net.sourceforge.deco.ant:analyze was searched.

The fix was to change the uri used in my build from net.sourceforge.deco.ant
to antlib:net.sourceforge.deco.ant.

But what is exactly wrong?

Was my initial declaration wrong?  Should it be mandatory to use exactly the
same URI in the typedef loading the antlib than in the antlib declaration
For the moment it is not mandatory, If you don't do, you may not notice that
you don't do.  But you might have the issue I had.  In that case, we should
at least have a warning (failing would break backward compatibility).

Or are was it the intention to let the user of an antlib freely choose its
uri?  I doubt.  But if it is, how can I reference my own tasks into the
antlib.xml file ?


Gilles Scokart

Reply via email to