1

I have two versions of the same jar (3.2 and 2.2.1) I need to use both of them but ivy evicts older revision. How to configure ivy to take two versions?

    <dependency org="asm" name="asm-all" rev="3.2">
      <artifact name="asm-all" type="jar"/>
    </dependency>

    <dependency org="asm" name="asm-all" rev="2.2.1">
    <artifact name="asm-all" type="jar"/>
    </dependency>
IgorOK
  • 1,652
  • 4
  • 18
  • 36

1 Answers1

2

You need to use ivy configurations. This is a very flexible mechanism to manage arbitrary groups of dependencies.

The example below places each version of the jar onto a separate configuration. This can be used later to create two classpaths, using the ivy cachepath task.

Example

ivy.xml

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

    <configurations>
        <conf name="compile1" description="Required to compile application1"/>
        <conf name="compile2" description="Required to compile application2"/>
    </configurations>

    <dependencies>
        <!-- compile1 dependencies -->
        <dependency org="asm" name="asm-all" rev="3.2" conf="compile1->master"/>

        <!-- compile2 dependencies -->
        <dependency org="asm" name="asm-all" rev="2.2.3" conf="compile2->master"/>
    </dependencies>

</ivy-module>

Notes:

  • Version 2.2.1 does not exist in Maven Central
  • Note the configuration mapping "??? -> master". In Maven the remote master configuration mapping resolves to the main module artifact without dependencies. (See)

build.xml

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

    <target name="init" description="Use ivy to resolve classpaths">
        <ivy:resolve/>

        <ivy:report todir='build/ivy' graph='false' xml='false'/>

        <ivy:cachepath pathid="compile1.path" conf="compile1"/>
        <ivy:cachepath pathid="compile2.path" conf="compile2"/>
    </target>

    <target name="clean" description="Clean built artifacts">
        <delete dir="build"/>
    </target>

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

</project>

Notes:

  • Always a good idea to generate an ivy report. It will tell you which dependencies exist on which ivy configuration.
  • This example shows ivy managing ANT paths. You can also use ivy configurations with the ivy retrieve task to populate a local "lib" directory when assembling something like a webapp WAR file.
Community
  • 1
  • 1
Mark O'Connor
  • 76,015
  • 10
  • 139
  • 185