3

I have the following build.xml solely to demonstrate the problem:

<project
    xmlns:ivy="antlib:org.apache.ivy.ant"
    name="test" default="test-ivy">
     <target name="test-ivy">
        <ivy:settings />
     </target>
</project>

When invoking it with Ant (1.7.1) I get:

$ ant
Buildfile: build.xml

test-ivy:

BUILD FAILED
/home/voops/test/build.xml:7: Problem: failed to create task or type antlib:org.apache.ivy.ant:settings
Cause: The name is undefined.
Action: Check the spelling.
Action: Check that any custom tasks/types have been declared.
Action: Check that any <presetdef>/<macrodef> declarations have taken place.
No types or tasks have been defined in this namespace yet

This appears to be an antlib declaration. 
Action: Check that the implementing library exists in one of:
        -/usr/share/ant/lib
        -/home/voops/.ant/lib
        -a directory added on the command line with the -lib argument


Total time: 0 seconds

However the Ivy jar does live in my ~/.ant/lib directory:

$ whoami
voops
$ls /home/voops/.ant/lib/ivy-2.3.0.jar
-rw-rw-r-- 1 voops voops 1222059 Nov 11 14:55 /home/voops/.ant/lib/ivy-2.3.0.jar

It appears that I have to manually indicate where the Ivy jar is located by adding the following element:

<taskdef uri="antlib:org.apache.ivy.ant" resource="org/apache/ivy/ant/antlib.xml"  classpath="${user.home}/.ant/lib/ivy-2.3.0.jar"/> 

... in my build.xml file. Once this element is added, the build succeeds.

Why is Ant not able to find Ivy even though the Ivy jar is located in the default ~/.ant/lib location and has to be explicitly told to look for it in the said location?

Update: It seems that the above element is only necessary for Ant 1.7.1. For Ant 1.8.2 or Ant 1.9.4, I don't have to add it.

Marcus Junius Brutus
  • 26,087
  • 41
  • 189
  • 331
  • 1
    possible duplicate of [Ivy fails to resolve a dependancy, unable to find cause](http://stackoverflow.com/questions/9853851/ivy-fails-to-resolve-a-dependancy-unable-to-find-cause) – Mark O'Connor Nov 17 '14 at 22:07
  • I had a similar problem on MacOSX (10.11.6 El Capitan). I installed ant and Ivy with the Brew package manager. One additional way is to define it manually using the -lib option, e.g.: ant clean compile -lib /usr/local/Cellar/ivy/2.4.0/libexec/ivy-2.4.0.jar – Christoph Dec 27 '16 at 21:20

1 Answers1

3

It's due to the XML namespace declaration in the buildfile:

xmlns:ivy="antlib:org.apache.ivy.ant"

Since the prefix ivy: is being used, the uri attribute is needed in the taskdef task to allow calling the task with the prefix:

An example is shown in the typedef documentation:

uri: The uri that this definition should live in. since Ant 1.6

EDIT:

The antlib indicates that Ant by default can load the correct resource if the antlib is placed in the home directory of Ant:

When Ant encounters a element with a namespace URI with this pattern, it will check to see if there is a resource of the name antlib.xml in the package directory in the default classpath.

M A
  • 71,713
  • 13
  • 134
  • 174
  • 1
    Yeah, but the exact same `build.xml` works OK with Ant 1.8.2 and the `taskdef` is *not* needed for that version of Ant. Also the error message seems to complain that the implementing library does not exist in `~/.ant/lib` when in fact it does exist. – Marcus Junius Brutus Nov 14 '14 at 11:53
  • You might want to take a look at [this page](https://ant.apache.org/manual/Types/antlib.html). As far I can tell, the `taskdef` is not required if the antlib is in the local Ant installation. Does your `~/.ant/` directory contain the installation for 1.7.1 or 1.8.2? – M A Nov 14 '14 at 12:07
  • My `~/.ant` directory contains a single directory: `lib` and inside that `lib` directory a single jar: `ivy-2.3.0.jar`. – Marcus Junius Brutus Nov 14 '14 at 12:33