This example is an illustration of how modules can be retrieved by multiple resolvers. Using multiple resolvers can be useful in many contexts, here are some examples:
In Ivy, the use of multiple resolvers is supported by one compound resolver called a chain resolver.
In our example, we will simply show how to use two resolvers, one on a local repository and one using maven2 repository.
The project is very simple and contains only one simple class: example.Hello.
It depends on two libraries: Apache commons-lang and a little test library (sources are included in jar file). The test library is used by the project to uppercase a string, and commons-lang is used to capitalize the same string.
Here is the content of the project:
Let's have a look at the ivy.xml file:
<ivy-module version="1.0">
<info organisation="org.apache" module="chained-resolvers"/>
<dependencies>
<dependency org="commons-lang" name="commons-lang" rev="2.0"/>
<dependency name="test" rev="1.0"/>
</dependencies>
</ivy-module>
As we expect, the ivy file declares to be dependent on the two libraries that the project use: commons-lang and test. Note that we don't specify the organisation for the dependency test, in this case Ivy assumes the same org as the declaring module, ie org.apache in this case.
The ivy settings is made in the settings directory it contains only one file: ivysettings.xml.
<ivysettings>
<settings defaultResolver="chain-example"/>
<resolvers>
<chain name="chain-example">
<filesystem name="libraries">
<artifact pattern="${ivy.settings.dir}/repository/[artifact]-[revision].[ext]" />
</filesystem>
<ibiblio name="ibiblio" m2compatible="true" />
</chain>
</resolvers>
</ivysettings>
This tag initializes ivy with some parameters. Here only one is used, the name of the resolver to use by default.
Under this tag, we can find the description of the resolvers that ivy will use. In our example, we have only one resolver, called "chain-example", which is quite special as it defines a list (a chain) of resolvers.
The resolvers put in the chain are :
That's it, we have configured a chain of resolvers!
I:\chained-resolvers\chainedresolvers-project>ant
Buildfile: src\example\chained-resolvers\chainedresolvers-project\build.xml resolve: [ivy:retrieve] :: Ivy 2.0.0-beta1-local-20071104204849 - 20071104204849 :: http://ant.apache.org/ivy/ :: [ivy:retrieve] :: loading settings :: file = C:\dev\data\opensource_workspace\ivy\src\example\chained-resolvers\config\ivysettings.xml [ivy:retrieve] :: resolving dependencies :: [ org.apache | chained-resolvers | working@BEN-ScokartG ] [ivy:retrieve] confs: [default] [ivy:retrieve] found [ commons-lang | commons-lang | 2.0 ] in ibiblio [ivy:retrieve] found [ org.apache | test | 1.0 ] in libraries [ivy:retrieve] downloading http://www.ibiblio.org/maven/commons-lang/jars/commons-lang-2.0.jar ... [ivy:retrieve] ............................................................. [ivy:retrieve] ......................................................... (165kB) [ivy:retrieve] .. (0kB) [ivy:retrieve] [SUCCESSFUL ] [ commons-lang | commons-lang | 2.0 ]/commons-lang.jar[jar] (5928ms) [ivy:retrieve] downloading C:\dev\data\opensource_workspace\ivy\src\example\chained-resolvers\config\repository\test-1.0.jar ... [ivy:retrieve] .. (1kB) [ivy:retrieve] [SUCCESSFUL ] [ org.apache | test | 1.0 ]/test.jar[jar] (10ms) [ivy:retrieve] :: resolution report :: --------------------------------------------------------------------- | | modules || artifacts | | conf | number| search|dwnlded|evicted|| number|dwnlded| --------------------------------------------------------------------- | default | 2 | 2 | 0 | 0 || 2 | 2 | --------------------------------------------------------------------- [ivy:retrieve] :: retrieving :: [ org.apache | chained-resolvers ] [ivy:retrieve] confs: [default] [ivy:retrieve] 2 artifacts copied, 0 already retrieved run: [mkdir] Created dir: C:\dev\data\opensource_workspace\ivy\src\example\chained-resolvers\chainedresolvers-project\build [javac] Compiling 1 source file to C:\dev\data\opensource_workspace\ivy\src\example\chained-resolvers\chainedresolvers-project\build [java] standard message :example world ! [java] capitalized by org.apache.commons.lang.WordUtils : Example World ! [java] upperCased by test.StringUtils : EXAMPLE WORLD ! BUILD SUCCESSFUL Total time: 12 seconds
We can see in the log of the resolve task, that the two dependencies have been retrieved (2 artifacts) and copied to the ivy cache directory (2 downloaded).
The run target succeed in using both commons-lang.jar comming from ibiblio repository and test.jar coming from the local repository.
This very simple example helps to see how to make a basic setting of two resolvers in a chain. The chain resolver's reference documentation is available for those who would like to know all the features offered by this resolver.
The most interesting things to know that you can try out from this basic example are:
go http://ant.apache.org/ivy/history/2.1.0-rc2/tutorial/multiple.html