Ivy fails to resolve a dependency, unable to find cause
Asked Answered
H

5

35

While using ivy:retrieve, it fails to resolve the dependency that should be downloaded. The output looks like this:

Buildfile: C:\Users\Simon\workspace\apollo\build.xml
init:
resolve:

BUILD FAILED
C:\Users\Simon\workspace\apollo\build.xml:42: Problem: failed to create task or type antlib:org.apache.ivy.ant:retrieve
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:
        -C:\Users\Simon\eclipse\plugins\org.apache.ant_1.8.2.v20120109-1030\lib
        -C:\Users\Simon\.ant\lib
        -a directory added on the command line with the -lib argument


Total time: 348 milliseconds

The relevant section of the build.xml looks like so:

  <target name="resolve" depends="init">
    <ivy:retrieve pattern="${lib}/[artifact]-[revision].[ext]" sync="true" />
  </target>

Here is also a list of what it should be downloading (from the build.xml)

  <target name="doc" depends="build">
    <javadoc sourcepath="${src}" classpathref="libraries" access="private" destdir="${doc}" windowtitle="Apollo">
      <doclet name="org.jboss.apiviz.APIviz" pathref="libraries">
        <param name="-sourceclasspath" value="${bin}" />
        <param name="-author" />
        <param name="-version" />
        <param name="-use" />
        <param name="-nopackagediagram" />
      </doclet>
      <doctitle><![CDATA[<h1>Apollo</h1>]]></doctitle>
      <link href="http://download.oracle.com/javase/6/docs/api/" />
      <link href="http://docs.jboss.org/netty/3.2/api/" />
      <link href="http://guava-libraries.googlecode.com/svn/trunk/javadoc/" />
      <link href="http://www.junit.org/apidocs/" />
      <link href="http://commons.apache.org/compress/apidocs/" />
      <link href="http://jruby.org/apidocs/" />
    </javadoc>
  </target>
Helmut answered 24/3, 2012 at 17:27 Comment(0)
E
58

ANT cannot find the ivy jar. Needs to be downloaded, extracted, and the ivy-x.y.z.jar placed into one of the following locations:

  • $ANT_HOME/lib
  • $HOME/.ant/lib

Enabling ivy

Ivy is packaged as an antlib, so to enable it you need to do the following

1) Declare the ivy namespace at the top of the build file

<project ..... xmlns:ivy="antlib:org.apache.ivy.ant">

2) Include the ivy jar in one of the ant library directories

Your error message indictates some of the possible locations for antlibs:

This appears to be an antlib declaration. 
Action: Check that the implementing library exists in one of:
        -C:\Users\Simon\eclipse\plugins\org.apache.ant_1.8.2.v20120109-1030\lib
        -C:\Users\Simon\.ant\lib
        -a directory added on the command line with the -lib argument

Note:

The beauty of an antlib is that you don't need to perform the taskdef (It's optional if you want to place the ivy jar in a non-standard location)

How to bootstrap a build

Even though ivy is an ANT sub-project, for some inexplicable reason ivy is not packaged with ANT....

I normally include the following target in my build files to setup a new environment:

<target name="bootstrap" description="Used to install the ivy task jar">
    <mkdir dir="${user.home}/.ant/lib"/>
    <get dest="${user.home}/.ant/lib/ivy.jar" src="http://search.maven.org/remotecontent?filepath=org/apache/ivy/ivy/2.2.0/ivy-2.2.0.jar"/>
</target>

It downloads the ivy jar from Maven Central.

Since all other ANT tasks can subsequently be downloaded using ivy, few people object to this little piece of ugliness at the top of the build file.

Estell answered 24/3, 2012 at 20:36 Comment(3)
quick feedback question: if ivy is in your ant_home/lib you don't need the taskdef? that was totally new for me :DNerves
Yes. It's puzzling why the ANT project doesn't ship the ivy jar by default.Housum
You may need to restart eclipse after running bootstrap.Motivation
N
11

If you can't put the ivy libs in the classpath for ant you will need to define it yourself:

<path id="ivy.lib.path">
    <fileset dir="path/to/dir/with/ivy/jar" includes="*.jar"/>
</path>
<taskdef resource="org/apache/ivy/ant/antlib.xml"
         uri="antlib:org.apache.ivy.ant" classpathref="ivy.lib.path"/>

This bit is missing from the getting started tutorial, but listed here: http://ant.apache.org/ivy/history/2.2.0/ant.html

Nerves answered 24/3, 2012 at 18:25 Comment(5)
Does it make any difference if im building within eclipse, which seems to have all the ant stuff?Helmut
@SimonSheehan ivy is not really a part of ant it is an additional library, so it does not maky any difference when using eclipse, you have to define the task (prior to the use of course).Nerves
in the build.xml im not entirely sure where im putting this. Just anywhere?Helmut
@SimonSheehan your init target would be a good place, the taskef has to be executed before any resolveNerves
If you're using Eclipse, you don't need to manually place the Ivy jars. Instead, use the Ivy Eclipse update site, install "Apache Ivy" and "Apache Ivy Ant Tasks".Presurmise
I
5

When you Run Ant task, in the classpath ensure that ivy.jar is there. In the eclipse -> Run As-> Ant Build -> Edit configuration -> Classpath tab. Even though Eclipse would have the ivy.jar in the ANT Home, for some reason it's not called.

Infirm answered 2/12, 2013 at 17:30 Comment(0)
E
1

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 
Ellanellard answered 27/12, 2016 at 21:19 Comment(0)
M
1

Even after adding ivy jar to the ant lib, it was not being picked up. Selecting the ANT_HOME again in Preferences->Ant->Runtime will cause the lib dir to be refreshed, and any libraries you have added there to be taken up.

Malave answered 14/2, 2017 at 10:4 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.