English 中文(简体)
Apache IVY - Resolvers
  • 时间:2024-11-03

Apache IVY - Resolvers


Previous Page Next Page  

Resolvers are used to find locations from where a pbrary 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 psts down the standard resolvers and their usage.

Sr.No. Name (Type) & Description
1

IvyRep (Standard)

Locates Ivy files on ivyrep and artifacts on ibibpo.
2

IBibpo (Standard)

Locates artifacts on ibibpo.
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 pst.
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 psted by an OSGi obr.xml.
15

Ecppse updatesite (Standard)

Resolve modules as OSGi bundles which are hosted on an Ecppse 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="antpb: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.tutorialspoint" name="test" rev="1.0"/>
   </dependencies>
</ivy-module>

Here we ve added two dependencies,one of commons-lang pbrary and another as test which we pubpshed in IVY - Pubpsh Task chapter.

ivysettings.xml


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

Here we ve added created a composite resolver using chain resolver which has two resolver, one named pbraries to locate pbaries on local repository and one named ibibpo on maven pubpc 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:ivy2uild.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
/pb/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 pubpc
[ivy:resolve]   found com.tutorialspoint#test;1.0 in local
[ivy:resolve]   found junit#junit;3.8.1 in pubpc
[ivy:resolve] downloading C:UsersAcer.ivy2localcom.tutorialspoint	est1.0
jarsapppcation.jar ...
[ivy:resolve] .. (1kB)
[ivy:resolve] .. (0kB)
[ivy:resolve]   [SUCCESSFUL ] com.tutorialspoint#test;1.0!apppcation.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 pubpc repository resolvers.

Advertisements