mirror of https://github.com/apache/ant-ivy
129 lines
5.9 KiB
HTML
129 lines
5.9 KiB
HTML
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01//EN" "http://www.w3.org/TR/html4/strict.dtd">
|
|
<!--
|
|
Licensed to the Apache Software Foundation (ASF) under one
|
|
or more contributor license agreements. See the NOTICE file
|
|
distributed with this work for additional information
|
|
regarding copyright ownership. The ASF licenses this file
|
|
to you under the Apache License, Version 2.0 (the
|
|
"License"); you may not use this file except in compliance
|
|
with the License. You may obtain a copy of the License at
|
|
|
|
http://www.apache.org/licenses/LICENSE-2.0
|
|
|
|
Unless required by applicable law or agreed to in writing,
|
|
software distributed under the License is distributed on an
|
|
"AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
|
|
KIND, either express or implied. See the License for the
|
|
specific language governing permissions and limitations
|
|
under the License.
|
|
-->
|
|
<html>
|
|
<head>
|
|
<META HTTP-EQUIV="Content-Type" CONTENT="text/html; charset=ISO-8859-1">
|
|
<script type="text/javascript">var xookiConfig = {level: 1};</script>
|
|
<script type="text/javascript" src="../xooki/xooki.js"></script>
|
|
</head>
|
|
<body>
|
|
<textarea id="xooki-source">
|
|
In some cases it may happen that your module descriptors (Ivy files, maven pom, ...) are located at one place and module artifacts (jars, ...) at another place.
|
|
|
|
Dual Resolver is used to address this kind of need, and this tutorial will show how to use it.
|
|
|
|
<h1>project description</h1>
|
|
Let's have a look at the src/example/dual directory in your ivy distribution.
|
|
It contains a build file and 3 directories:
|
|
<ul>
|
|
<li>settings: contains the ivy settings file</li>
|
|
<li>repository: a sample repository of ivy files</li>
|
|
<li>project: the project making use of ivy with dual resolver</li>
|
|
</ul>
|
|
|
|
<h2>the dual project</h2>
|
|
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:
|
|
<ul>
|
|
<li>build.xml: the ant build file for the project</li>
|
|
<li>ivy.xml: the ivy project file</li>
|
|
<li>src\example\Hello.java: the only class of the project</li>
|
|
</ul>
|
|
|
|
Let's have a look at the <b>ivy.xml</b> file:
|
|
<code>
|
|
<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>
|
|
</code>
|
|
|
|
As you can see, nothing special here... Indeed, it's the philosophy of ivy to keep ivy files independent of the way dependencies are resolved.
|
|
|
|
<h2>the <b>ivy</b> settings</h2>
|
|
The ivy settings is made in the settings directory; it contains only one file: ivysettings.xml.
|
|
|
|
<code>
|
|
<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>
|
|
</code>
|
|
|
|
Here we configure 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 exactly has 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 settings given in this resolver says that all ivy files are in the same directory, named like that: [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. It fulfills the given pattern and will thus be found by this 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 strictly necessary, since the second resolver in a dual resolver (the artifact resolver) is never asked to find module metadata.
|
|
|
|
<h1>walkthrough</h1>
|
|
<div class="step">
|
|
<h2>step 1 : preparation</h2>
|
|
Open a DOS or shell window, and go to the "dual" directory.
|
|
</div>
|
|
<div class="step">
|
|
<h2>step 2 : clean up</h2>
|
|
On the prompt type : ant<br>
|
|
This will clean up the entire project directory tree (compiled classes and retrieved libs) and ivy cache.
|
|
You can do it each time you want to clean up this example.
|
|
</div>
|
|
<div class="step">
|
|
<h2>step 3 : run the project</h2>
|
|
Goto project directory. And simply run <b>ant</b>.
|
|
<div class="shell"><pre>
|
|
I:\dual\project>ant
|
|
[<tutorial/log/dual.txt>]
|
|
</pre></div></div>
|
|
<br/>
|
|
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:
|
|
<code>
|
|
<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>
|
|
</code>
|
|
<br/>
|
|
So everything worked well, ivy file has been found in the repository directory and artifacts have been downloaded from ibiblio.
|
|
|
|
This kind of setup can be useful if you don't want to rely on 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 can lead to very flexible settings addressing most needs.
|
|
|
|
For full details about the dual resolver, have a look at the corresponding [[resolver/dual reference documentation]].
|
|
</textarea>
|
|
<script type="text/javascript">xooki.postProcess();</script>
|
|
</body>
|
|
</html>
|