eclipse Ivy 无法解决依赖项,无法找到原因

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/9853851/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-09-10 20:59:00  来源:igfitidea点击:

Ivy fails to resolve a dependency, unable to find cause

eclipseantivy

提问by Simon Sheehan

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

使用 时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

The relevant section of the build.xmllooks like so:

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

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

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

回答by Mark O'Connor

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 找不到常春藤罐。需要下载、解压,并将ivy-xyzjar放到以下位置之一:

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

Enabling ivy

启用常春藤

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

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

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

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

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

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

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

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

您的错误消息指出了 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)

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

How to bootstrap a build

如何引导构建

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

尽管 ivy 是一个 ANT 子项目,但出于某种莫名其妙的原因,ivy 并未与 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.

它从 Maven Central 下载 ivy jar。

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.

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

回答by oers

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

如果您不能将 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"/>

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

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

回答by Smart Coder

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.

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

回答by Christoph

I had a similar problem on MacOSX (10.11.6 El Capitan). I installed antand Ivywith the Brewpackage manager.

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

One additional way is to define it manually using the -lib option, e.g.:

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

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

回答by manojmo

Even after adding ivy jarto the ant lib, it was not being picked up. Selecting the ANT_HOMEagain in Preferences->Ant->Runtimewill cause the lib dirto be refreshed, and any libraries you have added there to be taken up.

即使在添加ivy jar到之后ant lib,它也没有被拾取。ANT_HOME再次选择Preferences->Ant->Runtime将导致lib dir刷新,并且您在那里添加的任何库都将被占用。