Multiple Resolvers
This example is an illustration of how artefacts can be retreived by multiple resolvers. Using multiple resolvers is very important when using continous integration. Indeed, in such environements, you can use multiple repositories and so multiple resolvers to retreive both released versions of projects than continous integrated versions produced for example with cruise-control. In our example, we will just show how to use two resolvers, one on a local repository and one using ibiblio repository.
project description
the project : chained-resolvers
The project is very simple and contains only one test 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:
- build.xml : the ant build file for the project
- ivy.xml : the ivy project file
- src\example\Hello.java : the only class of the project
Take a look at it's ivy.xml file :
<ivy-module version="1.0">
<info organisation="jayasoft" module="chained-resolvers" />
<dependencies>
<dependency org="apache" 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 : apache commons-lang.jar and test.jar.
the ivy configuration
The ivy configuration is made in the config directory it contains only one file: ivyconf.xml.
Let's analyse it.
<ivyconf>
<conf defaultResolver="chain-example" />
<resolvers>
<chain name="chain-example">
<filesystem name="libraries">
<artifact pattern="${ivy.conf.dir}/repository/[artifact]-[revision].[type]" />
</filesystem>
<ibiblio name="ibiblio" />
</chain>
</resolvers>
</ivyconf>
the conf tag
This tag initializes ivy with some parameters. Here only one is used, the name of the resolver to use by default.
the resolvers tag
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 :
- libraries : it is a file resolver. This one is configured to look for artefacts in the "repository" sub directory of the directory that contains the ivyconf.xml file.
- ibiblio : this resolver is a special one. It looks in the ibiblio maven repository to retreive the libraries.
walkthrough
step 1 : preparation
Open a DOS or shell window, and go to the "chained-resolvers" directory.
step 2 : clean directory tree
On the prompt type : ant
This will clean up the entire project directory tree and ivy cache. You can do it each time you want to clean up this example.
step 3 : run the project
Goto chainedresolvers-project directory. And simply run ant.
I:\chained-resolvers\chainedresolvers-project>ant Buildfile: build.xml configure: :: Ivy 1.0-rc3 - 20050421161206 :: http://ivy.jayasoft.org/ :: resolve: :: resolving dependencies :: jayasoft/chained-resolvers-working@xmen confs: [default] downloading http://www.ibiblio.org/maven/commons-lang/jars/commons-lang-2.0.jar(2.0) ... .................................... (165kB) [SUCCESSFUL ] apache/commons-lang-2.0/commons-lang.jar[jar] (5390ms) downloading file:/I:/chained-resolvers/config/repository/test-1.0.jar(1.0) ... . (1kB) [SUCCESSFUL ] jayasoft/test-1.0/test.jar[jar] (16ms) :: resolution report :: --------------------------------------------------------------------- | | modules || artifacts | | conf | number| search|dwnlded|evicted|| number|dwnlded| --------------------------------------------------------------------- | default | 2 | 2 | 0 | 0 || 2 | 2 | --------------------------------------------------------------------- :: retrieving :: jayasoft/chained-resolvers confs: [default] 2 artifacts copied, 0 already retrieved run: [mkdir] Created dir: I:\chained-resolvers\chainedresolvers-project\build [javac] Compiling 1 source file to I:\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: 9 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 comming from the local repository.