【问题标题】:Ivy fails to resolve a dependency, unable to find causeIvy 无法解决依赖关系,无法找到原因
【发布时间】:2012-04-08 21:04:08
【问题描述】:

在使用ivy:retrieve 时,它无法解析应下载的依赖项。输出如下所示:

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

build.xml 的相关部分如下所示:

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

这也是它应该下载的列表(来自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>

【问题讨论】:

    标签: eclipse ant ivy


    【解决方案1】:

    ANT 找不到常春藤罐。需要将 downloaded 提取出来,并将 ivy-x.y.z.jar 放入以下位置之一:

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

    启用常春藤

    Ivy 被打包为antlib,因此要启用它,您需要执行以下操作

    1) 在构建文件的顶部声明 ivy 命名空间

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

    2) 在 ant 库目录之一中包含 ivy jar

    您的错误消息指出了一些可能的 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
    

    注意:

    antlib 的美妙之处在于您不需要执行 taskdef(如果您想将 ivy jar 放在非标准位置,这是可选的)

    如何引导构建

    尽管 ivy 是一个 ANT 子项目,但由于某些莫名其妙的原因,ivy 没有与 ANT 打包......

    我通常在构建文件中包含以下目标来设置新环境:

    <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>
    

    它从 Maven Central 下载 ivy jar。

    由于所有其他 ANT 任务随后都可以使用 ivy 下载,因此很少有人反对构建文件顶部的这一小块丑陋。

    【讨论】:

    • 快速反馈问题:如果 ivy 在您的 ant_home/lib 中,您不需要 taskdef 吗?这对我来说是全新的:D
    • 是的。令人费解的是,为什么 ANT 项目默认不提供 ivy jar。
    • 运行bootstrap后可能需要重启eclipse。
    【解决方案2】:

    如果您不能将 ivy 库放在 ant 的类路径中,则需要自己定义:

    <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"/>
    

    入门教程中缺少这一点,但在此处列出:http://ant.apache.org/ivy/history/2.2.0/ant.html

    【讨论】:

    • 如果我在 eclipse 中构建它有什么不同吗,它似乎有所有的蚂蚁东西?
    • @SimonSheehan ivy 并不是 ant 的一部分,它是一个附加库,因此在使用 eclipse 时没有任何区别,您必须定义任务(当然在使用之前)。
    • 在 build.xml 中我不完全确定我把它放在哪里。就在任何地方?
    • @SimonSheehan 您的 init 目标将是一个好地方,taskef 必须在任何解决之前执行
    • 如果您使用的是 Eclipse,则无需手动放置 Ivy jar。相反,使用 Ivy Eclipse 更新站点,安装“Apache Ivy”和“Apache Ivy Ant Tasks”。
    【解决方案3】:

    当您运行 Ant 任务时,请确保在类路径中存在 ivy.jar。在 eclipse -> Run As-> Ant Build -> Edit configuration -> Classpath 选项卡中。尽管 Eclipse 在 ANT Home 中有 ivy.jar,但由于某种原因它没有被调用。

    【讨论】:

      【解决方案4】:

      我在 MacOSX (10.11.6 El Capitan) 上遇到了类似的问题。我用 Brew 包管理器安装了 antIvy

      另一种方法是使用 -lib 选项手动定义它,例如:

      ant clean compile -lib /usr/local/Cellar/ivy/2.4.0/libexec/ivy-2.4.0.jar 
      

      【讨论】:

        【解决方案5】:

        即使将ivy jar 添加到ant lib 后,它也没有被拾取。在Preferences-&gt;Ant-&gt;Runtime 中再次选择ANT_HOME 将导致lib dir 被刷新,并且您在其中添加的所有库都会被占用。

        【讨论】:

          猜你喜欢
          • 2016-01-06
          • 2012-12-24
          • 2012-07-07
          • 2019-11-04
          • 2023-03-29
          • 2016-02-16
          • 2017-02-20
          相关资源
          最近更新 更多