Apache IVY - Resolvers


Advertisements

Resolvers are used to find locations from where a library is to be downloaded. A dependency resolver also handles common tasks. Ivy provides two types of Resolvers.

  • Composite − A resolver which uses other resolvers to do its tasks.

  • Standard − A resolver performs the required tasks.

Standard Resolvers

Following table lists down the standard resolvers and their usage.

Sr.No. Name (Type) & Description
1

IvyRep (Standard)

Locates Ivy files on ivyrep and artifacts on ibiblio.
2

IBiblio (Standard)

Locates artifacts on ibiblio.
3

BinTray (Standard)

Locates artifacts on bintray.
4

Packager (Standard)

Locates Ivy files and packaging instructions via URLs, creates artifacts using instructions.
5

FileSystem (Standard)

Locates Ivy files and artifacts on local file system.
6

URL (Standard)

Locates Ivy files and artifacts on repositories which can be accessed using URLs.
7

MirroredURL (Standard)

Locates Ivy files and artifacts on repositories which can be accessed using URLs from a mirror list.
8

VFS (Standard)

Locates Ivy files and artifacts on repositories which can be accessed using Apache Commons VFS.
9

SSH (Standard)

Locates Ivy files and artifacts on repositories which can be accessed using SSH.
10

SFTP (Standard)

Locates Ivy files and artifacts on repositories which can be accessed using SFTP.
11

Jar (Standard)

Locates Ivy files and artifacts on repositories within a jar.
12

Chain (Composite)

Delegates the search to a chain of sub resolvers.
13

Dual (Composite)

Delegates the search to a one resolver and artifacts to another.
14

OBR (Standard)

Resolve modules as OSGi bundles listed by an OSGi obr.xml.
15

Eclipse updatesite (Standard)

Resolve modules as OSGi bundles which are hosted on an Eclipse update site.
16

OSGi-agg (Composite)

Delegates the search to a chain of sub resolvers supporting OSGi bundles.

Let's create Tester.java, build.xml and ivy.xml in a new project under E: > ivy2 folder similar to as described in IVY - Resolve Task chapter. Create a settings folder under E: > ivy2. Create the ivysettings.xml in the settings folder.

build.xml

<project name="test" default="resolve" xmlns:ivy="antlib:org.apache.ivy.ant">
   <property name = "build.dir" value = "build"/>
   <property name = "base.dir" value = ""/>
   <target name="resolve" description="resolve dependencies">
      <ivy:resolve />
   </target>
   <target name="compile" depends="resolve" description="Compile">
      <mkdir dir="build/classes" />
      <javac srcdir="src" destdir="build/classes">
         <classpath refid="new.classpath" />
      </javac>
   </target>
</project>

ivy.xml

<?xml version="1.0" encoding="ISO-8859-1"?>
<ivy-module version="2.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
   xsi:noNamespaceSchemaLocation="http://ant.apache.org/ivy/schemas/ivy.xsd">
   <info organisation="org.apache" module="chained-resolvers"/>
   <dependencies>
      <dependency org="commons-lang" name="commons-lang" rev="2.6" conf="default"/>
      <dependency org="com.howcodex" name="test" rev="1.0"/>
   </dependencies>
</ivy-module>

Here we've added two dependencies,one of commons-lang library and another as test which we published in IVY - Publish Task chapter.

ivysettings.xml

<ivysettings>
   <settings defaultResolver="multiresolver"/>
   <resolvers>
      <chain name="multiresolver">
         <filesystem name="libraries">
            <artifact pattern="${ivy.settings.dir}/repository/[artifact]-[revision].[ext]"/>
         </filesystem>
         <ibiblio name="ibiblio" m2compatible="true"/>
      </chain>
   </resolvers>
</ivysettings>

Here we've added created a composite resolver using chain resolver which has two resolver, one named libraries to locate libaries on local repository and one named ibiblio on maven public repository.

Building the project

As we've all the files ready. Just go the console. Navigate to E: > ivy2 folder and run the ant command.

E:\ivy > ant

Ivy will come into action, resolving the dependencies, you will see the following result.

Buildfile: E:\ivy2\build.xml

resolve:
[ivy:resolve] :: Apache Ivy 2.5.0 - 20191020104435 :: https://ant.apache.org/ivy
/ ::
[ivy:resolve] :: loading settings :: url = jar:file:/E:/Apache/apache-ant-1.9.14
/lib/ivy-2.5.0.jar!/org/apache/ivy/core/settings/ivysettings.xml
[ivy:resolve] :: resolving dependencies :: org.apache#chained-resolvers;working@
Acer-PC
[ivy:resolve]   confs: [default]
[ivy:resolve]   found commons-lang#commons-lang;2.6 in public
[ivy:resolve]   found com.howcodex#test;1.0 in local
[ivy:resolve]   found junit#junit;3.8.1 in public
[ivy:resolve] downloading C:\Users\Acer\.ivy2\local\com.howcodex\test\1.0\
jars\application.jar ...
[ivy:resolve] .. (1kB)
[ivy:resolve] .. (0kB)
[ivy:resolve]   [SUCCESSFUL ] com.howcodex#test;1.0!application.jar (13ms)

[ivy:resolve] :: resolution report :: resolve 1085ms :: artifacts dl 22ms
      ---------------------------------------------------------------------
      |                  |            modules            ||   artifacts   |
      |       conf       | number| search|dwnlded|evicted|| number|dwnlded|
      ---------------------------------------------------------------------
      |      default     |   3   |   3   |   1   |   0   ||   5   |   1   |
      ---------------------------------------------------------------------

BUILD SUCCESSFUL
Total time: 9 seconds

In the logs you can verify that we have used both local and public repository resolvers.

Advertisements