Added: ant/ivy/site/target/history/2.2.0/tutorial/dependence.html URL: http://svn.apache.org/viewvc/ant/ivy/site/target/history/2.2.0/tutorial/dependence.html?rev=1005260&view=auto ============================================================================== --- ant/ivy/site/target/history/2.2.0/tutorial/dependence.html (added) +++ ant/ivy/site/target/history/2.2.0/tutorial/dependence.html Wed Oct 6 21:25:29 2010 @@ -0,0 +1,409 @@ + + + + + + + + +Project dependencies | Apache Ivy + + + + + + + + + + +
+ + + + + + + + + + + + + +
+ +
+ +
+ + + + +
+ + +
+ + +
+ + + + + + + +
+
+ +

Project dependencies

+
This tutorial will show you how to use Ivy when one of your projects depends on another.

For our example, we will have two projects, depender and dependee, where the depender project uses/requires the dependee project. This example will help illustrate two things about Ivy: +
    +
  • that dependencies defined by parent projects (dependee) will automatically be retrieved for use by child projects (depender)
  • +
  • that child projects can retrieve the "latest" version of the dependee project
  • +
+

projects used

+

dependee

+The dependee project is very simple. It depends on the apache library commons-lang and contains only one class: standalone.Main which provides two services: +
    +
  • return the version of the project
  • +
  • capitalize a string using org.apache.commons.lang.WordUtils.capitalizeFully
  • +
+Here is the content of the project: +
    +
  • build.xml: the ant build file for the project
  • +
  • ivy.xml: the project ivy file
  • +
  • src\standalone\Main.java: the only class of the project
  • +
+Take a look at the ivy.xml file: +
+<ivy-module version="1.0">
<info organisation="org.apache" module="dependee"/>
<dependencies>
<dependency org="commons-lang" name="commons-lang" rev="2.0"/>
</dependencies>
</ivy-module> +
+ +The ivy file declares only one dependency, that being the apache commons-lang library.

depender

+The depender project is very simple as well. It declares only one dependency on the latest version of the dependee project, and it contains only one class, depending.Main, which does 2 things: +
    +
  • gets the version of the standalone project by calling standalone.Main.getVersion()
  • +
  • transforms a string by calling standalone.Main.capitalizeWords(str)
  • +
+Take a look at the ivy.xml file: +
+<ivy-module version="1.0">
<info organisation="org.apache" module="depender"/>
<dependencies>
<dependency name="dependee" rev="latest.integration" />
</dependencies>
</ivy-module> +
+ +

settings

+The Ivy settings are defined in two files located in the settings directory: +
    +
  • ivysettings.properties: a property file
  • +
  • ivysettings.xml: the file containing the settings
  • +
+ +Let's have a look at the ivysettings.xml file: +
+<ivysettings>
<properties file="${ivy.settings.dir}/ivysettings.properties"/>
<settings defaultCache="${ivy.settings.dir}/ivy-cache" defaultResolver="libraries"/>
<resolvers>
<filesystem name="projects">
<artifact pattern="${repository.dir}/[artifact]-[revision].[ext]" />
<ivy pattern="${repository.dir}/[module]-[revision].xml" />
</filesystem>
<ibiblio name="libraries" m2compatible="true" usepoms="false" />
</resolvers>
<modules>
<module organisation="org.apache" name="dependee" resolver="projects"/>
</modules>
</ivysettings> +
+The file contains four main tags: properties, settings, resolvers and modules.

properties

+This tag loads some properties for the Ivy process, just like Ant does.

settings

+This tag initializes some parameters for the Ivy process. In this case, the directory that Ivy will use to cache artifacts will be in a sub directory called ivy-cache of the directory containing the ivysettings.xml file itself.
The second parameter, tells Ivy to use a resolver named "libraries" as its default resolver. More information can be found in the settings reference documentation.

resolvers

+This tag defines the resolvers to use. Here we have two resolvers defined: "projects" and "libraries".
The filesystem resolver called "projects" is able to resolve the internal dependencies by locating them on the local filesystem.
The ibiblio resolver called "libraries" is able to find dependencies on the maven 2 repository, but doesn't use maven poms.

modules

+The modules tag allows you to configure which resolver should be used for which module. Here the setting tells Ivy to use the "projects" resolver for all modules having an organisation of org.apache and module name of dependee. This actually corresponds to only one module, but a regular expression could be used, or many other types of expressions (like glob expressions).

All other modules (i.e. all modules but org.apache#dependee), will use the default resolver ("libraries").

walkthrough

+
+

step 1: preparation

+Open a DOS or shell window, and go to the src/example/dependence directory. +
+
+

step 2: clean directory tree

+On the prompt type: ant +This will clean up the entire project directory tree. You can do this each time you want to clean up this example. +
+
+

step 3: publication of dependee project

+Go to dependee directory and publish the project +
+[ivy@apache:/ivy/dependence/dependee]$ ant publish
+Buildfile: /ivy/dependence/dependee/build.xml
+
+resolve:
+[ivy:retrieve] :: Ivy 2.2.0 - 20100923230623 :: http://ant.apache.org/ivy/ ::
+[ivy:retrieve] :: loading settings :: file = /ivy/dependence/settings/ivysettings.xml
+[ivy:retrieve] DEPRECATED: 'defaultCache' is deprecated, use 'caches[@defaultCacheDir]' instead (file://ivy/dependence/settings/ivysettings.xml)
+[ivy:retrieve] :: resolving dependencies :: org.apache#dependee;working@apache
+[ivy:retrieve] 	confs: [default]
+[ivy:retrieve] 	found commons-lang#commons-lang;2.0 in libraries
+[ivy:retrieve] downloading http://repo1.maven.org/maven2/commons-lang/commons-lang/2.0/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 (3260ms)
+[ivy:retrieve] :: resolution report :: resolve 530ms :: artifacts dl 3260ms
+	---------------------------------------------------------------------
+	|                  |            modules            ||   artifacts   |
+	|       conf       | number| search|dwnlded|evicted|| number|dwnlded|
+	---------------------------------------------------------------------
+	|      default     |   1   |   1   |   0   |   0   ||   1   |   1   |
+	---------------------------------------------------------------------
+[ivy:retrieve] :: retrieving :: org.apache#dependee
+[ivy:retrieve] 	confs: [default]
+[ivy:retrieve] 	1 artifacts copied, 0 already retrieved (165kB/31ms)
+
+compile:
+    [mkdir] Created dir: /ivy/dependence/dependee/build/classes
+    [javac] /ivy/dependence/dependee/build.xml:60: warning: 'includeantruntime' was not set, defaulting to build.sysclasspath=last; set to false for repeatable builds
+    [javac] Compiling 1 source file to /ivy/dependence/dependee/build/classes
+
+jar:
+[propertyfile] Creating new property file: /ivy/dependence/dependee/build/classes/version.properties
+      [jar] Building jar: /ivy/dependence/dependee/build/dependee.jar
+
+publish:
+[ivy:publish] :: delivering :: org.apache#dependee;working@apache :: 1 :: release :: Thu Sep 23 23:15:49 CEST 2010
+[ivy:publish] 	delivering ivy file to /ivy/dependence/dependee/build/ivy.xml
+[ivy:publish] :: publishing :: org.apache#dependee
+[ivy:publish] 	published dependee to /ivy/dependence/settings/repository/dependee-1.jar
+[ivy:publish] 	published ivy to /ivy/dependence/settings/repository/dependee-1.xml
+     [echo] project dependee released with version 1
+
+BUILD SUCCESSFUL
+Total time: 6 seconds
+
+
+What we see here: +
    +
  • the project depends on 1 library (1 artifact)
  • +
  • the library was not in the Ivy cache and so was downloaded (1 downloaded)
  • +
  • the project has been released under version number 1
  • +
+
+As you can see, the call to the publish task has resulted in two main things: +
    +
  • the delivery of a resolved ivy file to build/ivy.xml.
  • +This has been done because by default, the publish task not only publishes artifacts, but also its ivy file. So it has looked to the path where the ivy file to publish should be, using the artifactspattern: ${build.dir}/[artifact].[ext]. For an ivy file, this resolves to build/ivy.xml. Because this file does not exist, it automatically makes a call to the deliver task which delivers a resolved ivy file to this destination.
    +
  • the publication of artifact 'dependee' and its resolved ivy file to the repository.
  • +Both are just copies of the files found in the current project, or more precisely, those in the build directory. This is because the artifactspattern has been set to ${build.dir}/[artifact].[ext], so the dependee artifact is found at build/dependee.jar and the ivy file in build/ivy.xml. And because we have asked the publish task to publish them using the "projects" resolver, these files are copied to repository\dependee-1.jar and to repository\dependee-1.xml, respecting the artifact and ivy patterns of our settings (see above). +
+ +
+

step 4: running the depender project

+Go to directory depender and run ant +
+[ivy@apache:/ivy/dependence/depender]$ ant 
+Buildfile: /ivy/dependence/depender/build.xml
+
+clean:
+
+resolve:
+[ivy:retrieve] :: Ivy 2.2.0 - 20100923230623 :: http://ant.apache.org/ivy/ ::
+[ivy:retrieve] :: loading settings :: file = /ivy/dependence/settings/ivysettings.xml
+[ivy:retrieve] DEPRECATED: 'defaultCache' is deprecated, use 'caches[@defaultCacheDir]' instead (file://ivy/dependence/settings/ivysettings.xml)
+[ivy:retrieve] :: resolving dependencies :: org.apache#depender;working@apache
+[ivy:retrieve] 	confs: [default]
+[ivy:retrieve] 	found org.apache#dependee;1 in projects
+[ivy:retrieve] 	[1] org.apache#dependee;latest.integration
+[ivy:retrieve] 	found commons-lang#commons-lang;2.0 in libraries
+[ivy:retrieve] downloading /ivy/dependence/settings/repository/dependee-1.jar ...
+[ivy:retrieve] .. (1kB)
+[ivy:retrieve] .. (0kB)
+[ivy:retrieve] 	[SUCCESSFUL ] org.apache#dependee;1!dependee.jar (16ms)
+[ivy:retrieve] :: resolution report :: resolve 343ms :: artifacts dl 47ms
+	---------------------------------------------------------------------
+	|                  |            modules            ||   artifacts   |
+	|       conf       | number| search|dwnlded|evicted|| number|dwnlded|
+	---------------------------------------------------------------------
+	|      default     |   2   |   1   |   1   |   0   ||   2   |   1   |
+	---------------------------------------------------------------------
+[ivy:retrieve] :: retrieving :: org.apache#depender
+[ivy:retrieve] 	confs: [default]
+[ivy:retrieve] 	2 artifacts copied, 0 already retrieved (167kB/47ms)
+
+compile:
+    [mkdir] Created dir: /ivy/dependence/depender/build/classes
+    [javac] /ivy/dependence/depender/build.xml:71: warning: 'includeantruntime' was not set, defaulting to build.sysclasspath=last; set to false for repeatable builds
+    [javac] Compiling 1 source file to /ivy/dependence/depender/build/classes
+
+run:
+     [java] you are using version 1 of class standalone.Main
+     [java] standard message : i am depending.Main and standalone.Main will do the job for me
+     [java]     [standalone.Main] capitalizing string "i am depending.Main and standalone.Main will do the job for me" using org.apache.commons.lang.WordUtils
+     [java] capitalized message : I Am Depending.main And Standalone.main Will Do The Job For Me
+
+BUILD SUCCESSFUL
+Total time: 3 seconds
+
+
+What we see here: +
    +
  • the project depends on 2 libraries (2 artifacts)
  • +
  • one of the libraries was in the cache because there was only 1 download (1 downloaded)
  • +
  • Ivy retrieved version 1 of the project "dependee". The call to standalone.Main.getVersion() has returned 1. If you look in the depender/lib directory, you should see dependee-1.jar which is the version 1 artifact of the project "dependee"
  • +
  • the call to standalone.Main.capitalizeWords(str) succeed, which means that the required library was in the classpath. If you look at the lib directory, you will see that the library commons-lang-2.0.jar was also retrieved. This library was declared as a dependency of the "dependee" project, so Ivy retrieves it (transitively) along with the dependee artifact.
  • +
+
+
+

step 5: new version of dependee project

+Like we did before in step 3, publish the dependee project again. This will result in a new version of the project being published. +
+[ivy@apache:/ivy/dependence/dependee]$ ant publish
+Buildfile: /ivy/dependence/dependee/build.xml
+
+resolve:
+[ivy:retrieve] :: Ivy 2.2.0 - 20100923230623 :: http://ant.apache.org/ivy/ ::
+[ivy:retrieve] :: loading settings :: file = /ivy/dependence/settings/ivysettings.xml
+[ivy:retrieve] DEPRECATED: 'defaultCache' is deprecated, use 'caches[@defaultCacheDir]' instead (file://ivy/dependence/settings/ivysettings.xml)
+[ivy:retrieve] :: resolving dependencies :: org.apache#dependee;working@apache
+[ivy:retrieve] 	confs: [default]
+[ivy:retrieve] 	found commons-lang#commons-lang;2.0 in libraries
+[ivy:retrieve] :: resolution report :: resolve 109ms :: artifacts dl 0ms
+	---------------------------------------------------------------------
+	|                  |            modules            ||   artifacts   |
+	|       conf       | number| search|dwnlded|evicted|| number|dwnlded|
+	---------------------------------------------------------------------
+	|      default     |   1   |   0   |   0   |   0   ||   1   |   0   |
+	---------------------------------------------------------------------
+[ivy:retrieve] :: retrieving :: org.apache#dependee
+[ivy:retrieve] 	confs: [default]
+[ivy:retrieve] 	0 artifacts copied, 1 already retrieved (0kB/0ms)
+
+compile:
+    [javac] /ivy/dependence/dependee/build.xml:60: warning: 'includeantruntime' was not set, defaulting to build.sysclasspath=last; set to false for repeatable builds
+
+jar:
+[propertyfile] Updating property file: /ivy/dependence/dependee/build/classes/version.properties
+      [jar] Building jar: /ivy/dependence/dependee/build/dependee.jar
+
+publish:
+   [delete] Deleting: /ivy/dependence/dependee/build/ivy.xml
+[ivy:publish] :: delivering :: org.apache#dependee;working@apache :: 2 :: release :: Thu Sep 23 23:15:56 CEST 2010
+[ivy:publish] 	delivering ivy file to /ivy/dependence/dependee/build/ivy.xml
+[ivy:publish] :: publishing :: org.apache#dependee
+[ivy:publish] 	published dependee to /ivy/dependence/settings/repository/dependee-2.jar
+[ivy:publish] 	published ivy to /ivy/dependence/settings/repository/dependee-2.xml
+     [echo] project dependee released with version 2
+
+BUILD SUCCESSFUL
+Total time: 1 second
+
+
+Now if you look in your repository folder, you will find 2 versions of the dependee project.
Let's look at it: +
I:\dependee>dir ..\settings\repository /w

[.] [..] dependee-1.jar dependee-1.xml dependee-2.jar dependee-2.xml

I:\dependee>
+
+OK, now our repository contains two versions of the project dependee, so other projects can refer to either version. +
+

step 6: get the new version in depender project

+What should we expect if we run the depender project again? It should: +
    +
  • retrieve version 2 as the latest.integration version of the dependee project
  • +
  • display version 2 of dependee project
  • +
+Let's try it!! +
+[ivy@apache:/ivy/dependence/depender]$ ant 
+Buildfile: /ivy/dependence/depender/build.xml
+
+clean:
+
+resolve:
+[ivy:retrieve] :: Ivy 2.2.0 - 20100923230623 :: http://ant.apache.org/ivy/ ::
+[ivy:retrieve] :: loading settings :: file = /ivy/dependence/settings/ivysettings.xml
+[ivy:retrieve] DEPRECATED: 'defaultCache' is deprecated, use 'caches[@defaultCacheDir]' instead (file://ivy/dependence/settings/ivysettings.xml)
+[ivy:retrieve] :: resolving dependencies :: org.apache#depender;working@apache
+[ivy:retrieve] 	confs: [default]
+[ivy:retrieve] 	found org.apache#dependee;1 in projects
+[ivy:retrieve] 	[1] org.apache#dependee;latest.integration
+[ivy:retrieve] 	found commons-lang#commons-lang;2.0 in libraries
+[ivy:retrieve] :: resolution report :: resolve 94ms :: artifacts dl 15ms
+	---------------------------------------------------------------------
+	|                  |            modules            ||   artifacts   |
+	|       conf       | number| search|dwnlded|evicted|| number|dwnlded|
+	---------------------------------------------------------------------
+	|      default     |   2   |   0   |   0   |   0   ||   2   |   0   |
+	---------------------------------------------------------------------
+[ivy:retrieve] :: retrieving :: org.apache#depender
+[ivy:retrieve] 	confs: [default]
+[ivy:retrieve] 	2 artifacts copied, 0 already retrieved (167kB/31ms)
+
+compile:
+    [mkdir] Created dir: /ivy/dependence/depender/build/classes
+    [javac] /ivy/dependence/depender/build.xml:71: warning: 'includeantruntime' was not set, defaulting to build.sysclasspath=last; set to false for repeatable builds
+    [javac] Compiling 1 source file to /ivy/dependence/depender/build/classes
+
+run:
+     [java] you are using version 1 of class standalone.Main
+     [java] standard message : i am depending.Main and standalone.Main will do the job for me
+     [java]     [standalone.Main] capitalizing string "i am depending.Main and standalone.Main will do the job for me" using org.apache.commons.lang.WordUtils
+     [java] capitalized message : I Am Depending.main And Standalone.main Will Do The Job For Me
+
+BUILD SUCCESSFUL
+Total time: 2 seconds
+
+
+OK, we got what we expected as the run target shows that we are using version 2 of the main class of the dependee project. If we take a look at the resolve target results, we see that one artifact has been downloaded to the ivy cache. In fact, this file is the same version 2 of the dependee project that is in the repository, but now all future retrievals will pull it from your ivy-cache directory. +
+ + +
+
+ + + + + + + + + + + + +
+ + Added: ant/ivy/site/target/history/2.2.0/tutorial/dual.html URL: http://svn.apache.org/viewvc/ant/ivy/site/target/history/2.2.0/tutorial/dual.html?rev=1005260&view=auto ============================================================================== --- ant/ivy/site/target/history/2.2.0/tutorial/dual.html (added) +++ ant/ivy/site/target/history/2.2.0/tutorial/dual.html Wed Oct 6 21:25:29 2010 @@ -0,0 +1,223 @@ + + + + + + + + +Dual Resolver | Apache Ivy + + + + + + + + + + +
+ + + + + + + + + + + + + +
+ +
+ +
+ + + + +
+ + +
+ + +
+ + + + + + + +
+
+ +

Dual Resolver

+
In some cases, your module descriptions (i.e. Ivy files, maven poms) are located separately from the module artifacts (i.e. jars). So what can you do about it?

Use a Dual resolver! And this tutorial will show you how.

project description

+Let's have a look at the src/example/dual directory in your Ivy distribution.
It contains a build file and 3 directories: +
    +
  • settings: contains the ivy settings file
  • +
  • repository: a sample repository of ivy files
  • +
  • project: the project making use of Ivy with dual resolver
  • +
+ +

the dual project

+The project is very simple and contains only one simple class: example.Hello +It depends on two libraries: Apache commons-lang and Apache commons-httpclient.

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
  • +
+ +Let's have a look at the ivy.xml file: +
+<ivy-module version="1.0">
<info organisation="org.apache" module="hello-ivy"/>
<dependencies>
<dependency org="commons-httpclient" name="commons-httpclient" rev="2.0.2"/>
<dependency org="commons-lang" name="commons-lang" rev="2.0"/>
</dependencies>
</ivy-module> +
+ +As you can see, nothing special here... Indeed, Ivy's philosophy is to keep ivy files independent of the way dependencies are resolved.

the ivy settings

+The ivy settings are defined in the ivysettings.xml file located in the settings directory. Here is what it contains, followed by an explanation.
+
+<ivysettings>
<settings defaultResolver="dual-example"/>
<resolvers>
<dual name="dual-example">
<filesystem name="ivys">
<ivy pattern="${ivy.settings.dir}/../repository/[module]-ivy-[revision].xml" />
</filesystem>
<ibiblio name="ibiblio" m2compatible="true" usepoms="false" />
</dual>
</resolvers>
</ivysettings> +
+ +Here we configured one resolver, the default one, which is a dual resolver. This dual resolver has two sub resolvers: the first is what is called the "ivy" or "metadata" resolver of the dual resolver, and the second one is what is called the "artifact" resolver. It is important that the dual resolver has exactly two sub resolvers in this given order.

The metadata resolver, here a filesystem one, is used only to find module descriptors, in this case Ivy files. The setting shown here tells Ivy that all ivy files are in the repository directory, named with the pattern: [module]-ivy-[revision].xml. If we check the repository directory, we can confirm that it contains a file named commons-httpclient-ivy-2.0.2.xml. This file matches the pattern, so it will be found by the resolver.

The artifact resolver is simply an ibiblio one, configured in m2compatible mode to use the maven 2 repository, with usepoms="false" to make sure it won't use maven 2 metadata. Note that this isn't necessary, since the second resolver in a dual resolver (the artifact resolver) is never asked to find module metadata.

walkthrough

+
+

step 1 : preparation

+Open a DOS or shell window, and go to the dual directory. +
+
+

step 2 : clean up

+On the prompt type : ant
+This will clean up the entire project directory tree (compiled classes and retrieved libs) and the Ivy cache. You can run this each time you want to clean up this example. +
+
+

step 3 : run the project

+Go to the project directory. And simply run ant. +
+[ivy@apache:/ivy/dual/project]$ ant 
+Buildfile: /ivy/dual/project/build.xml
+
+resolve:
+[ivy:retrieve] :: Ivy 2.2.0 - 20100923230623 :: http://ant.apache.org/ivy/ ::
+[ivy:retrieve] :: loading settings :: file = /ivy/dual/settings/ivysettings.xml
+[ivy:retrieve] :: resolving dependencies :: org.apache#hello-ivy;working@apache
+[ivy:retrieve] 	confs: [default]
+[ivy:retrieve] 	found commons-httpclient#commons-httpclient;2.0.2 in ivys
+[ivy:retrieve] 	found commons-logging#commons-logging;1.0.4 in ibiblio
+[ivy:retrieve] 	found commons-lang#commons-lang;2.0 in ibiblio
+[ivy:retrieve] downloading http://repo1.maven.org/maven2/commons-httpclient/commons-httpclient/2.0.2/commons-httpclient-2.0.2.jar ...
+[ivy:retrieve] .................................................................................................................................................................................................................................................................................................................................................................................................................................................... (220kB)
+[ivy:retrieve] .. (0kB)
+[ivy:retrieve] 	[SUCCESSFUL ] commons-httpclient#commons-httpclient;2.0.2!commons-httpclient.jar (3853ms)
+[ivy:retrieve] downloading http://repo1.maven.org/maven2/commons-lang/commons-lang/2.0/commons-lang-2.0.jar ...
+[ivy:retrieve] ................................................................................................................................................................................................................................................................................................................................................ (165kB)
+[ivy:retrieve] .. (0kB)
+[ivy:retrieve] 	[SUCCESSFUL ] commons-lang#commons-lang;2.0!commons-lang.jar (1826ms)
+[ivy:retrieve] downloading http://repo1.maven.org/maven2/commons-logging/commons-logging/1.0.4/commons-logging-1.0.4.jar ...
+[ivy:retrieve] .......................................................................... (37kB)
+[ivy:retrieve] .. (0kB)
+[ivy:retrieve] 	[SUCCESSFUL ] commons-logging#commons-logging;1.0.4!commons-logging.jar (1341ms)
+[ivy:retrieve] :: resolution report :: resolve 1076ms :: artifacts dl 7036ms
+	---------------------------------------------------------------------
+	|                  |            modules            ||   artifacts   |
+	|       conf       | number| search|dwnlded|evicted|| number|dwnlded|
+	---------------------------------------------------------------------
+	|      default     |   3   |   3   |   1   |   0   ||   3   |   3   |
+	---------------------------------------------------------------------
+[ivy:retrieve] :: retrieving :: org.apache#hello-ivy
+[ivy:retrieve] 	confs: [default]
+[ivy:retrieve] 	3 artifacts copied, 0 already retrieved (423kB/47ms)
+
+run:
+    [mkdir] Created dir: /ivy/dual/project/build
+    [javac] /ivy/dual/project/build.xml:58: warning: 'includeantruntime' was not set, defaulting to build.sysclasspath=last; set to false for repeatable builds
+    [javac] Compiling 1 source file to /ivy/dual/project/build
+     [java] standard message : hello ivy !
+     [java] capitalized by org.apache.commons.lang.WordUtils : Hello Ivy !
+     [java] head status code with httpclient: 200
+     [java] now check if httpclient dependency on commons-logging has been realized
+     [java] found logging class in classpath: interface org.apache.commons.logging.Log
+
+BUILD SUCCESSFUL
+Total time: 10 seconds
+
+
+
+As you can see, Ivy not only downloaded commons-lang and commons-httpclient, but also commons-logging. Indeed, commons-logging is a dependency of httpclient, as we can see in the httpclient ivy file found in the repository directory: +
+<ivy-module version="1.0">
<info
organisation="commons-httpclient"
module="commons-httpclient"
revision="2.0.2"
status="release"
publication="20041010174300"/>
<dependencies>
<dependency org="commons-logging" name="commons-logging" rev="1.0.4" conf="default"/>
</dependencies>
</ivy-module> +
+
+So everything seemed to work. The ivy file was found in the repository directory and the artifacts have been downloaded from ibiblio.

This kind of setup can be useful if you don't want to rely on the maven 2 repository for metadata, or if you want to take full advantage of Ivy files for some or all modules. Combining chain and dual resolvers should give you enough flexibility to meet almost any requirement.

For full details about the dual resolver, have a look at the corresponding reference documentation.
+
+
+ + + + + + + + + + + + +
+ + Added: ant/ivy/site/target/history/2.2.0/tutorial/multiple.html URL: http://svn.apache.org/viewvc/ant/ivy/site/target/history/2.2.0/tutorial/multiple.html?rev=1005260&view=auto ============================================================================== --- ant/ivy/site/target/history/2.2.0/tutorial/multiple.html (added) +++ ant/ivy/site/target/history/2.2.0/tutorial/multiple.html Wed Oct 6 21:25:29 2010 @@ -0,0 +1,226 @@ + + + + + + + + +Multiple Resolvers | Apache Ivy + + + + + + + + + + +
+ + + + + + + + + + + + + +
+ +
+ +
+ + + + +
+ + +
+ + +
+ + + + + + + +
+
+ +

Multiple Resolvers

+
This tutorial is an example of how modules can be retrieved by multiple resolvers. Using multiple resolvers can be useful in many contexts. For example: +
    +
  • separating integration builds from releases
  • +
  • using a public repository for third party modules and a private one for internal modules
  • +
  • use a repository for storing modules which are not accurate in an unmanaged public repository
  • +
  • use a local repository to expose builds made on one developer's station
  • +
+ +In Ivy, the use of multiple resolvers is supported by a compound resolver called the chain resolver.

In our example, we will simply show you how to use two resolvers, one on a local repository and one using the maven2 repository.

project description

+

the project: chained-resolvers

+The project is very simple and contains only one simple class: example.Hello.

It depends on two libraries: Apache's commons-lang and a custom library named test (sources are included in test-1.0jar 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
  • +
+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'd expect, the ivy file declares this module to be dependent on the two libraries it uses: 'commons-lang' and 'test'. Note that we didn't specify the org for the dependency 'test'. When we exclude org, Ivy assumes it is in the same org as the declaring module. (i.e. 'org.apache').

the ivy settings

+The settings are defined in the ivysettings.xml file located in the settings directory of the project. Below are its contents, followed by an explanation of what it's doing.
+
+<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> +
+

the settings tag

+This tag initializes Ivy with some parameters. Here only one parameter is set, the name of the resolver to use by default.

the resolvers tag

+The resolvers section defines the list of resolvers that Ivy will use to locate artifacts. In our example, we have only one resolver named "chain-example", which is unique in that it defines a list (hence a chain) of resolvers.
The resolvers in this chain are: +
    +
  • libraries : It is a filesystem resolver, so looks at a directory structure to retrieve the artifacts. This one is configured to look in the repository sub directory of the directory that contains the ivysettings.xml file.
  • +
  • ibiblio : It looks in the ibiblio maven repository to retrieve the artifacts.
  • +
+ +That's it, we have just configured a chain of resolvers!

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 this each time you want to clean up this example.
+
+In almost all examples, we provide a clean target as default target. Since most examples use the same Ivy cache, you will clean the whole Ivy cache each time you call this target.

Cleaning the Ivy cache is something you can do without fear (except performance): it's only a cache, so everything can be (and should be) obtained again from repositories. This may sound strange to those coming from maven 2 land. But remember that in Ivy, the cache is not a local repository and the two are completely isolated. +
+
+
+

step 3: run the project

+Go to chained-resolvers project directory. And simply run ant.
+
+[ivy@apache:/ivy/chained-resolvers/chainedresolvers-project]$ ant 
+Buildfile: /ivy/chained-resolvers/chainedresolvers-project/build.xml
+
+resolve:
+[ivy:retrieve] :: Ivy 2.2.0 - 20100923230623 :: http://ant.apache.org/ivy/ ::
+[ivy:retrieve] :: loading settings :: file = /ivy/chained-resolvers/settings/ivysettings.xml
+[ivy:retrieve] :: resolving dependencies :: org.apache#chained-resolvers;working@apache
+[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://repo1.maven.org/maven2/commons-lang/commons-lang/2.0/commons-lang-2.0.jar ...
+[ivy:retrieve] ........................................................................................................................................................................................................................................................................................................................................... (165kB)
+[ivy:retrieve] .. (0kB)
+[ivy:retrieve] 	[SUCCESSFUL ] commons-lang#commons-lang;2.0!commons-lang.jar (2745ms)
+[ivy:retrieve] downloading /ivy/chained-resolvers/settings/repository/test-1.0.jar ...
+[ivy:retrieve] .. (1kB)
+[ivy:retrieve] 	[SUCCESSFUL ] org.apache#test;1.0!test.jar (16ms)
+[ivy:retrieve] :: resolution report :: resolve 4836ms :: artifacts dl 2761ms
+	---------------------------------------------------------------------
+	|                  |            modules            ||   artifacts   |
+	|       conf       | number| search|dwnlded|evicted|| number|dwnlded|
+	---------------------------------------------------------------------
+	|      default     |   2   |   2   |   1   |   0   ||   2   |   2   |
+	---------------------------------------------------------------------
+[ivy:retrieve] :: retrieving :: org.apache#chained-resolvers
+[ivy:retrieve] 	confs: [default]
+[ivy:retrieve] 	2 artifacts copied, 0 already retrieved (166kB/62ms)
+
+run:
+    [mkdir] Created dir: /ivy/chained-resolvers/chainedresolvers-project/build
+    [javac] /ivy/chained-resolvers/chainedresolvers-project/build.xml:58: warning: 'includeantruntime' was not set, defaulting to build.sysclasspath=last; set to false for repeatable builds
+    [javac] Compiling 1 source file to /ivy/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: 10 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).

Also notice that the 'run' Ant target succeeded in using both commons-lang.jar coming from the ibiblio repository and test.jar coming from the local repository.

Going further

+This very simple example helps us see how to set up 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.

Below are a few more interesting things worth knowing about chain resolvers. After reading them, go ahead and try tweaking this example using your new wealth of knowledge! +
    +
  • a chain is not limited to two nested resolvers, you can use as many as you want
  • +
  • by setting returnFirst="true", you can have a chain which stops as soon as it has found a result for a given module
  • +
  • by setting dual="true", the full chain will be used both for module descriptors and artifacts, while setting dual="false", the resolver in the chain which found the module descriptor (if any) is also used for artifacts
  • +
+ + +
+
+ + + + + + + + + + + + +
+ +