Ivy - resolve same dependency twice (with two different versions), to two different files

你离开我真会死。 提交于 2019-12-06 08:11:39

问题


I have a special situation where I need to package up some jars, and I need BOTH versions of a jar. My ivy definitions looks like this:

<dependency org="blah" name="blahname" rev="1.0.0" conf="baseline->default" />

I would like the same dependency resolved twice, once with version 1.0.0 and another with say version 2.0.0. Is that possible? What's the easiest way to achieve this.


回答1:


Use ivy configurations to create and manage custom groups of dependencies.

Example

ivy.xml

<ivy-module version="2.0">
    <info organisation="com.myspotontheweb" module="demo"/>

    <configurations>
        <conf name="group1" description="First group of dependencies"/>
        <conf name="group2" description="Second group of dependencies"/>
    </configurations>

    <dependencies>
        <dependency org="commons-lang" name="commons-lang" rev="2.6" conf="group1->default"/>
        <dependency org="commons-lang" name="commons-lang" rev="2.0" conf="group2->default"/>
    </dependencies>

</ivy-module>

build.xml

<project name="demo" default="resolve" xmlns:ivy="antlib:org.apache.ivy.ant">

    <target name="resolve">
        <ivy:resolve/>

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

</project>

Notes:

  • This example uses the retrieve task to populate the "lib" directory. See also the "cachepath" and "cachefileset" tasks.

Results

Lib directory is populated with the desired jars.

$ tree
.
|-- build.xml
|-- ivy.xml
`-- lib
    |-- group1
    |   `-- commons-lang-2.6.jar
    `-- group2
        `-- commons-lang-2.0.jar


来源:https://stackoverflow.com/questions/10941293/ivy-resolve-same-dependency-twice-with-two-different-versions-to-two-differ

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!