如何解决模块 X 的多个工件被检索到 Apache Ivy 中的同一个文件?

Posted

技术标签:

【中文标题】如何解决模块 X 的多个工件被检索到 Apache Ivy 中的同一个文件?【英文标题】:How do I solve Multiple artifacts of the module X are retrieved to the same file in Apache Ivy? 【发布时间】:2011-11-09 04:06:09 【问题描述】:

我使用 ANT 将我的东西部署到 Tomcat。但是我遇到了缺少依赖项的问题,我想添加 Ivy,因为它已被推荐。

现在我将它添加到我的 build.xml 文件中:

<!-- Ivy settings start-->

    <condition property="ivy.home" value="$env.IVY_HOME">
        <isset property="env.IVY_HOME" />
    </condition>


    <target name="download-ivy" unless="offline" description="Download Ivy">
        <mkdir dir="$ivy.jar.dir"/>
            <!-- download Ivy from web site so that it can be used even without any special installation -->
        <get src="http://repo2.maven.org/maven2/org/apache/ivy/ivy/$ivy.install.version/ivy-$ivy.install.version.jar" 
            dest="$ivy.jar.file" usetimestamp="true"/>
    </target>


    <target name="init-ivy" depends="download-ivy" description="Initialize Ivy">
        <!-- try to load ivy here from ivy home, in case the user has not already dropped
        it into ant's lib dir (note that the latter copy will always take precedence).
        We will not fail as long as local lib dir exists (it may be empty) and
        ivy is in at least one of ant's lib dir or the local lib dir. -->
        <path id="ivy.lib.path">
            <fileset dir="$ivy.jar.dir" includes="*.jar"/>
        </path>
        <taskdef resource="org/apache/ivy/ant/antlib.xml"
        uri="antlib:org.apache.ivy.ant" classpathref="ivy.lib.path"/>
    </target>

    <target name="update" depends="init-ivy" description="Download project dependencies">
        <!-- edited for brevity -->

        <ivy:retrieve pattern="lib/[conf]/[artifact]-[revision].[ext]" />
        <!-- edited for brevity -->
    </target>


    <target name="clean-all" depends="clean" description="Purge ivy cache">
        <ivy:cleancache/>
    </target>

<!-- Ivy settings end-->

这是我的 ivy.xml:

<ivy-module version="2.0">
    <info organisation="org.apache" module="hello-ivy"/>
    <dependencies>
        <dependency org="commons-lang" name="commons-lang" rev="2.1"/>
    </dependencies>
</ivy-module>

这是我的日志:

Buildfile: C:\Users\Jansu\workspace\HelloWorld\build.xml
download-ivy:
      [get] Getting: http://repo2.maven.org/maven2/org/apache/ivy/ivy/2.2.0/ivy-2.2.0.jar
      [get] To: C:\Users\Jansu\.ant\lib\ivy-2.2.0.jar
      [get] Not modified - so not downloaded
init-ivy:
update:
[ivy:retrieve] :: Ivy 2.2.0 - 20100923230623 :: http://ant.apache.org/ivy/ ::
[ivy:retrieve] :: loading settings :: url = jar:file:/C:/Users/Jansu/.ant/lib/ivy-2.2.0.jar!/org/apache/ivy/core/settings/ivysettings.xml
[ivy:retrieve] :: resolving dependencies :: org.apache#hello-ivy;working@Jansu-PC
[ivy:retrieve]  confs: [default]
[ivy:retrieve]  found commons-lang#commons-lang;2.1 in public
[ivy:retrieve] downloading http://repo1.maven.org/maven2/commons-lang/commons-lang/2.1/commons-lang-2.1.jar ...
[ivy:retrieve] ................................................................................................................................................................................................................................................................................................................................................................................................................. (202kB)
[ivy:retrieve] .. (0kB)
[ivy:retrieve]  [SUCCESSFUL ] commons-lang#commons-lang;2.1!commons-lang.jar (1704ms)
[ivy:retrieve] downloading http://repo1.maven.org/maven2/commons-lang/commons-lang/2.1/commons-lang-2.1-sources.jar ...
[ivy:retrieve] ........................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................ (255kB)
[ivy:retrieve] .. (0kB)
[ivy:retrieve]  [SUCCESSFUL ] commons-lang#commons-lang;2.1!commons-lang.jar(source) (1819ms)
[ivy:retrieve] downloading http://repo1.maven.org/maven2/commons-lang/commons-lang/2.1/commons-lang-2.1-javadoc.jar ...
[ivy:retrieve] .........................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................
[ivy:retrieve] ................................................................................................................................................................................................................................................................ (518kB)
[ivy:retrieve] .. (0kB)
[ivy:retrieve]  [SUCCESSFUL ] commons-lang#commons-lang;2.1!commons-lang.jar(javadoc) (2817ms)
[ivy:retrieve] :: resolution report :: resolve 2094ms :: artifacts dl 6357ms
    ---------------------------------------------------------------------
    |                  |            modules            ||   artifacts   |
    |       conf       | number| search|dwnlded|evicted|| number|dwnlded|
    ---------------------------------------------------------------------
    |      default     |   1   |   1   |   1   |   0   ||   3   |   3   |
    ---------------------------------------------------------------------
[ivy:retrieve] :: retrieving :: org.apache#hello-ivy
[ivy:retrieve]  confs: [default]

这是错误:

BUILD FAILED
    C:\Users\Jansu\workspace\HelloWorld\build.xml:177: impossible to ivy retrieve: java.lang.RuntimeException: problem during retrieve of org.apache#hello-ivy: java.lang.RuntimeException: Multiple artifacts of the module commons-lang#commons-lang;2.1 are retrieved to the same file! Update the retrieve pattern  to fix this error.

    Total time: 11 seconds

似乎错误来自这种模式? :

<ivy:retrieve pattern="lib/[conf]/[artifact]-[revision].[ext]" />

但对我来说它看起来很可靠。

有什么建议吗?

【问题讨论】:

【参考方案1】:

您必须扩展您的模式以包含该类型,以便每个工件都有自己的本地文件:

<ivy:retrieve pattern="lib/[conf]/[artifact]-[type]-[revision].[ext]" />

或者,如果您不需要源代码和 javadoc,您可以将依赖项更改为:

<ivy-module version="2.0">
    <info organisation="org.apache" module="hello-ivy"/>
    <dependencies>
        <dependency org="commons-lang" name="commons-lang" rev="2.1" conf="default->master"/>
    </dependencies>
</ivy-module>

这只会检索依赖项的 master-conf(jar)。

【讨论】:

我收到了这个[ivy:retrieve] Problem occurred while parsing ivy file: Cannot add dependency 'commons-lang#commons-lang;2.1' to configuration 'master' of module org.apache#hello-ivy;working@Jansu-PC because this configuration doesn't exist! in file:/C:/Users/Jansu/workspace/HelloWorld/ivy.xml BUILD FAILED 现在可以了,谢谢,但是你怎么知道在conf=后面写什么。这就是我需要知道的关于常春藤的全部信息吗?现在我只是在这里编写新的依赖项,然后将它们全部下载。为什么这比不使用 ivy 手动下载这些更好?仅仅因为,它节省了几秒钟还是...? “节省几秒钟”? “如何节省一些时间”?在 Ivy/Maven 之前,我花了好几天的时间迭代地发现和下载一层又一层的依赖关系。

以上是关于如何解决模块 X 的多个工件被检索到 Apache Ivy 中的同一个文件?的主要内容,如果未能解决你的问题,请参考以下文章

如何强制 Maven 使用我的本地存储库而不是去远程存储库检索工件?

如何在Nexus 2.x中提供对工件的最新快照的URL访问?

如何导入 Apache Flink SNAPSHOT 工件?

如何使一个模块依赖于另一个模块工件?

如何更新工件构建模块 ID

如何将 gps 模块的实时位置检索到我的数据库中,以便我可以在多个应用程序中使用它?