Está en la página 1de 33

Ivy - Beginners Guide

Maithilish
maithilish@gmail.com
Contents
Chapter 1 Introduction...................................................................................................................2
Manual v/s Automated Dependency Management..................................................2
About this Guide......................................................................................................2
art I Ivy..................................................................................................................................!
Chapter 2 Installation....................................................................................................................."
#est the installation..................................................................................................."
Chapter ! Ivy #erminology............................................................................................................$
Ivy #as%s...................................................................................................................$
Chapter " &esolve #as%.................................................................................................................'
Dependency line ......................................................................................................(
Ivy Cache..................................................................................................................(
Chapter $ Cachepath #as%.............................................................................................................)
Chapter ' &etrieve #as%...............................................................................................................1*
Chapter + Ivy Core Concepts.......................................................................................................11
&epositories............................................................................................................11
,ettings -iles...........................................................................................................11
atterns...................................................................................................................11
&esolvers................................................................................................................1!
De.ault &esolvers...................................................................................................1$
Chapter ( Install #as%..................................................................................................................1+
/ocal &epository....................................................................................................1+
0verriding the de.ault settings...............................................................................1)
,hared repository....................................................................................................21
Moving &epository to 1eb ,erver.........................................................................21
&epository Manager...............................................................................................22
Chapter ) ublish tas%.................................................................................................................2!
art II IvyD2.........................................................................................................................2$
Chapter 1* Installation.................................................................................................................2'
3pdate ,ite.............................................................................................................2'
Manual installation.................................................................................................2'
Chapter 11 &esolve......................................................................................................................2+
Chapter 12 &etrieve.....................................................................................................................!*
Chapter 1! 0ther #abs o. IvyD2 Managed /ibraries..................................................................!2
,ettings #ab............................................................................................................!2
Advanced #ab.........................................................................................................!2
Chapter 1" Going .urther.............................................................................................................!!
Introduction 2
Chapter 1 Introduction
In 4ava pro5ects it is al6ays convenient to reuse the popular libraries li%e Apache Commons7 /og"5 etc.
rather than develop your o6n libraries .rom scratch. In simple pro5ects7 that depends on couple o. libraries7
dependency can be managed by adding these 5ars to the pro5ect manually. 8ut as pro5ect becomes more
sophisticated they may end up 6ith do9ens o. e:ternal 5ars. 1hen pro5ect is developed by a team then
members may add these 5ars to pro5ect independently and may lead to bro%en builds. In all these situations
dependency management becomes ;uite cumbersome.
Apache Maven is most popular build manager .or 4ava pro5ects 6hich combines build manager and
dependency manager. Maven also comes 6ith other .eatures li%e pro5ect in.ormation to handle the complete
build process o. 4ava pro5ects. 8ut .or some reason you don<t 6ant all these .eatures or pre.er Ant .or build
process then Ivy 6ould be the ne:t best choice .or automated dependency management.
Ivy is a popular dependency manager .rom Apache. It .its per.ectly 6ith Ant to automate dependency
management and improves the pro5ect build system. IvyD2 is a 2clipse plugin 6hich integrates Ivy
dependency management 6ith 2clipse.
Manual v/s Automated Dependency Management
-or .airly long time I use to maintain a lib directory 6here all important libraries li%e apache=commons7 5dbc
drivers7 dom"57 log"5 etc 6ith corresponding source7 5avadoc 5ars are placed. -or each pro5ect in 2clipse 5ars
are added manually to pro5ect<s build path. #here 6as also additional e..orts o. lin%ing respective source and
5avadoc to the library so that they are available in conte:t help. /ater 6hile distributing the application same
set o. 5ar .ile paths are to be added to Ant build .ile. Developer has to be care.ul to include proper version o.
these libraries to avoid runtime errors in production. >o doubt it is lot o. unnecessary 6or%.
In a recent pro5ect7 list o. dependencies gre6 beyond a do9en. It 6as high time to move to automated
dependency management. 1ith Ivy things become e:tremely simple. All that 6as re;uired 6as to add a
ivy.:ml .ile to pro5ect and build path. #his simple .ile enumerates the dependencies and version. IvyD2 6ill
ta%e care all lin%ages li%e source and 5avadoc etc. ersonal lib directory is no longer necessary. Ivy 6ill .etch
the re;uired dependencies .rom a public repository and places them in its cache .or .urther use. 1hen a ne6
library is re;uired .or pro5ect 5ust add a dependency line to ivy.:ml and Ivy 6ill ta%e care to rest o. the chore.
About this Guide
Ivy is a po6er.ul piece o. so.t6are and highly con.igurable. Ivy site has some e:cellent tutorials and detailed
re.erence documentation. 8ut a beginner may soon get lost by multiple con.igurable options and struggle to
get it right in .irst try.
#his step=by=step guide e:plains ho6 to set up Ivy7 use Ivy to automate dependency management7 set up
enterprise repository and .inally integrate Ivy 6ith 2clipse through IvyD2.
8asic ob5ective o. this guide it to provide clear understanding o. Ivy to the beginners. As such 6e have used
minimum re;uired con.iguration to get the tas% done in all e:amples. 0nce readers are com.ortable 6ith
basic concepts7 they can e:plore the advanced .eatures o. Ivy to suit their re;uirement.
Ivy - Beginners Guide
Ivy 3
Part I Ivy
#his part covers
installation o. Ivy
basic tas%s li%e &esolve and &etrieve
core concepts li%e pattern7 resolvers etc.
setting up o. local and shared repository
publish your o6n modules to repository
Ivy - Beginners Guide
Installation 4
Chapter 2 Installation
1e re;uire Apache=ant and Apache=ivy to 6or% through this part o. boo%. In case Ant is already installed in
your system ignore the ant installation commands. 1e are installing ant at /opt/ant7 but any other location is
.ine. Ad5ust settings accordingly. Do6nload latest Ivy and Ant .rom Apache site.
tar -C /opt/ant/ -xzvf apache-ant-1.8.2-bin.tar.gz
tar -xzvf apache-ivy-2.2.0-bin-with-deps.tar.gz
cp apache-ivy-2.2.0/ivy-2.2.0.jar /opt/ant/apache-ant-1.8.2/lib
export !"#$%&'(/opt/ant/apache-ant-1.8.2
export )"$(*)"$+*!"#$%&'/bin
A>#?@0M2 and A#@ has to be set to run ant. 2:ports may be moved to .bash?pro.ile in /inu: so that
they are al6ays set.
Test the installation
#hroughout this guide a 6or% directory li%e A@0M2/6or% is used to run e:amples. 8ut it can be anything.
-or readability and consistency 6e 6ill be using phrases li%e create a .ile in 6or% dir7 add a ivy.:ml to
6or%dir and run .rom 6or% dir etc. 6hich simply means 6or% .rom some directory. -or each e:ercise start
6ith a clean directory to avoid any errors and ensuing con.usion.
>o6 to test the installation add .ollo6ing build.:ml .ile to 6or% dir
build.xml
,project na-e(.test ivy. defa/lt(.test.
x-lns+ivy(.antlib+org.apache.ivy.ant.0
,target na-e(.test. description(."est ivy installation.0
,ivy+settings /0
,/target0
,/project0
and run ant
ant
,uccess.ul build indicates that ant and ivy installation is .ine. #ypical error 6ould be
build.:mlB$B roblemB .ailed to create tas% or type antlibBorg.apache.ivy.antBsettings
this may be due to
environment variable A>#?@0M2 not set properly
ivy.5ar is missing .rom A>#?@0M2/lib
Ivy - Beginners Guide
Ivy Terminology 5
Chapter 3 Ivy Terminology
8rie. description o. some o. terms used by Ivy are
Term Description
0rganisation >ame o. company7 individual or team 6hich created the so.t6are. 2:ampleB
org.apache etc.
Module Module is a sel.=contained7 reusable unit o. so.t6are. Module typically has
version. 2:ampleB commons=lang7 log"5 etc.
Module Descriptor Cml .ile containing the description or metadata o. a module. 3sually this .ile
is named as ivy.:ml
Arti.act Arti.act is a single .ile ready .or distribution. In 5ava it is typically a 5ar .ile.
8ut it may be o. any .ile type li%e 9ip7 g9 etc. Module contains one or more
arti.acts.
4ar7 ,ource 5ar and 4avadoc 5ar are e:amples o. arti.act.
#ype #ype denotes category o. arti.act. 2:ampleB 5ar7 src7 source7 doc7 bundle etc.
Arti.act .ile name 2:tension 2:tension o. an arti.act. 2:ampleB 5ar7 9ip7 tar7 tar.g9 etc
Module &evision uni;ue revision number or version name o. particular release o. module.
,tatus o. &evision indicates ho6 stable a module revision is. Ivy de.ines .ollo6ing status
integrationB continuous build7 a nightly build etc.
milestoneB distributed but not yet .inished .ully.
releaseB tested and completed.
&epository Distribution site 6here ivy can .ind modules7 descriptors and arti.acts.
&epository can be public7 local or shared.
Ivy ,ettings Ivy 6or%s 6ithout any speci.ic con.iguration through de.ault settings. 8ut
de.ault settings can be overridden through :ml based settings .ile. 3sually
this .ile is named as ivysettings.:ml
Ivy Tasks
Ivy comes 6ith it o6n set o. tas%s 6hich can be called .rom Ant build .ile. #his guide covers .ollo6ing Ivy
#as%s
Task Name Description
&esolve &esolves the dependencies described in ivy.:ml and places the resolved
dependencies in ivy cache.
Cachepath Constructs an ant path consisting o. arti.acts in ivy cache 6hich can be
re.erred in other ant tas%s through Ant path mechanism.
&etrieve Copies the resolved dependencies .rom cache to a speci.ied directory
Install Installs a module to a speci.ied repository. In this guide Install tas% is used to
install libraries .rom public repository to a local/shared repository
ublish ublish a module to a repository.
Ivy - Beginners Guide
Resolve Task 6
Chapter 4 Resolve Task
&esolve tas% resolve dependencies described in ivy.:ml and put the resolved dependencies in the ivy cache.
Create a pac%age in 6or% dir
-1dir -p src/in/ex/ivy
Add .ollo6ing 5ava .ile to this dir.
Example.java
pac1age in.ex.ivy2
i-port org.apache.co--ons.lang.3tring4tils2
p/blic class 'xa-ple 5
p/blic static void -ain63tring78 args9 5
3tring string ( 3tring4tils./pperCase6.:vy ;eginner </ide.92
3yste-.o/t.println6string92
=
=
#his simple programme depends on commons=lang module .rom Apache.
Instead o. adding commons=lang pac%age to build path manually7 let us delegate the dependency
management to Ivy.
Add a .ile named ivy.:ml to 6or% dir.
ivy.xml
,>x-l version(.1.0. encoding(.:3%-88?@-1.>0
,ivy--od/le version(.2.0.
x-lns+xsi(.http+//www.wA.org/2001/B&C3che-a-instance.
xsi+no!a-espace3che-aCocation(.http+//ant.apache.org/ivy/sche-as/ivy.xsd.0
,info organisation(.in.ex. -od/le(.ivy-exa-ple. stat/s(.integration.0
,/info0
,dependencies0
,dependency org(.co--ons-lang. na-e(.co--ons-lang. rev(.2.D. /0
,/dependencies0
,/ivy--od/le0
ivy.:ml provides details about our pro5ect and dependencies. Ivy 6ill read this .ile and manage the
dependencies.
#his .ile has ! sections
1. ivy=module B this is standard root element 6ith version7schema etc.
2. in.o B this section is in.ormation about our pro5ect.
organisation B organisation or company.
module B name o. the pro5ect
status B release status D milestone7 integration or release.
Ivy - Beginners Guide
Resolve Task 7
!. dependencies B one or more dependencies o. this pro5ect.
dependency B
org B organisation 6hich provides the module
name B module name
rev B revision or version o. the module
1e are indicating that our pro5ect is dependent on commons=lang revision 2.'
Add ant build.:ml to 6or% dir.
build.xml
,project na-e(.ivy exa-ple. defa/lt(.resolve.
x-lns+ivy(.antlib+org.apache.ivy.ant.0
,target na-e(.resolve. description(.resolve dependencies with ivy.0
,ivy+resolve /0
,/target0
,/project0
In pro5ect element 6e have added ivy namespace so that 6e can use ivy tas%s. EivyBresolve /F in target
named resolve is the resolve tas%. #his 6ill resolve the dependencies described in ivy.:ml and places the
resolved dependencies in ivy cache.
>o6 run ant. Ivy goes into 5ob o. resolving the dependencies 6e mentioned in ivy.:ml. I. you are connected
to internet Ivy 6ill try to .etch the commons=lang revision 2.' .rom a public repository.
Ivy .etches the commons=lang .rom net and places them in cache.
Console output sho6s that resolve step has gone through success.ully. In.ormation about the &esolve is
provided in last portion o. output
con.
ivy is using de.ault con.iguration
module
0ne module is resolved. As Ivy has do6nloaded this module
d6nlded is one.
arti.acts
there are ! arti.acts i.e. 5ar7 source and 5avadoc in this module.
As Ivy has do6nloaded them d6nlded is three.
In this e:ample 6e have not told Ivy 6here to loo% .or modules. Ivy uses concept called &esolvers 6hich
de.ines location o. a repository. Ivy has used the de.ault resolvers. De.ault public resolver points to
httpB//repo1.maven.org/maven2. Ivy has .etched the module .rom this repository.
In case a module itsel. has other dependencies then Ivy 6ill .etch all re;uired dependencies. #hese are
%no6n as transitive dependencies. -or e:ample log"5 is depends on 5ava:.mail7 5unit7 5ermanio.spec and oro.
Dependency line Edependency orgGHlog"5H nameGHlog"5H revGH1.2.1'H/F 6ill do6nload log"5 plus .our
dependent modules. -or some reason you don<t 6ant to do6nload dependent module then add
Ivy - Beginners Guide
Resolve Task 8
transitiveGI.alseI to dependency line.
Dependency line
#he dependency line Edependency orgGHcommons=langH nameGHcommons=langH revGH2.'H /F in ivy.:ml
re;uires couple o. e:planations.
@o6 to construct this line. Jisit httpB//mvnrepository.com/ and search .or module. -or e:ample a search .or
commons=lang 6ill yield all matching commons module. ,elect commons=lang among them. Jersion
available in the repository 6ill be displayed
Clic% on 2.$ or 6hatever version you are interested in to get the dependency line .or Ivy among other build
systems li%e maven7 grape etc. ,elect Ivy tab and there you 6ill have the e:act dependency line as re;uired
.or Ivy. Cut and paste this line to ivy.:ml
Another thing about this particular dependency line is that organisation is mentioned as commons=lang 6here
as it should have been apache.org. -or some reasons 6hile uploading the module to maven repository it 6as
mentioned as commons=lang instead o. apache.org and it is continuing li%e6ise. &ather than ma%ing
assumption about the org or name it is better to search .or the module in maven repository and copy the
dependency line as provided there.
Ivy ache
0n .irst run resolve 6ill .etch the arti.acts .rom a repository and place them in cache. ,ubse;uent call to
resolve either .rom this pro5ect or another pro5ect .or the resolved arti.act7 resolve tas% .inishes 6ithout any
delay. #hese is because Ivy .inds dependencies in cache.
8y de.ault ivy cache is at A@0M2/.ivy2. 8eyond that 6e need not bother much about the cache.
Ivy - Beginners Guide
ac!e"at! Task #
Chapter 5 Cachepath Task
Constructs an ant path consisting o. arti.acts in ivy cache.
In last chapter 6e used &esolve tas% to resolve and put the arti.acts into cache. >o6 to compile the program
6e re;uire classpath re.erence to these arti.acts. Cachepath tas% constructs the ant path .or this.
Change build.:ml as .ollo6s
build.xml
,project na-e(.ivy exa-ple. defa/lt(.resolve.
x-lns+ivy(.antlib+org.apache.ivy.ant.0
,target na-e(.resolve. description(.resolve dependencies with ivy.0
,ivy+resolve /0
,ivy+cachepath pathid(.defa/lt.classpath./0
,/target0
,target na-e(.co-pile. depends(.resolve. description(.Co-pile.0
,-1dir dir(.b/ild/classes. /0
,javac srcdir(.src. destdir(.b/ild/classes.0
,classpath refid(.defa/lt.classpath. /0
,/javac0
,/target0
,/project0
A.ter resolve ivy constructs Ant path named de.ault.classpath. #his path points to resolved arti.acts in cache.
/ater in 5avac tas% 6e have re.erred it 6ith re.id. In this e:ample 5avac 6ill use the resolved arti.acts in
cache to compile the 2:ample.5ava
In case ivyBcachepath is called directly 6ithout a ivyBresolve then resolve is internally called be.ore
constructing the path.
>ote D It is to be noted that arti.acts are not copied .rom cache either by &esolve or by Cachepath tas%.
Cachepath constructs a path points to arti.acts in cache.
Ivy - Beginners Guide
Retrieve Task $%
Chapter 6 Retrieve Task
Instead o. cachepath e:plained in last chapter7 better approach is to copy the dependencies to pro5ect space
and use standard ant path creation.
&etrieve tas% copies resolved dependencies to a speci.ied location in .ilesystem. 0nce dependencies are
properly copied to pro5ect 6or%space use standard ant path creation to build the pro5ect.
Change the build.:ml as .ollo6s
build.xml
,project na-e(.ivy exa-ple. defa/lt(.resolve.
x-lns+ivy(.antlib+org.apache.ivy.ant.0
,target na-e(.resolve. description(.Eesolve and Eetrieve with ivy.0
,ivy+resolve /0
,ivy+retrieve sync(.tr/e. type(.jar. /0
,/target0
,/project0
A.ter resolve ivy 6ill copy the resolved arti.acts .rom cache to a ne6ly created lib directory.

In case ivyBretrieve is called directly 6ithout a ivyBresolve then resolve is internally called be.ore retrieving
the arti.acts.
Important attributes that are used in this tas% are
!ync set to true 6ill ensure that any e:tra .iles in lib directory is deleted.
Type set to 5ar tells ivy to copy only 5ar arti.acts. ,ource and 5avadoc arti.acts are ignored.
3se pattern attribute to change location 6here retrieved .iles are to be placed
,ivy+retrieve sync(.tr/e. type(.jar. pattern(.-yfolder/7artifact8-7revision8.7ext8. /0
#his 6ill retrieve the arti.acts to my.older directory. 0ther aspects o. the pattern 6ill be e:plained later.
,ome modules li%e log"5 use bundle as type .or 5ar arti.act. 3se .ollo6ing line to handle that variation
,ivy+retrieve sync(.tr/e. type(.jarFb/ndle. /0
Ivy - Beginners Guide
Ivy ore once"ts $$
Chapter 7 Ivy Core Concepts
"epositories
#ill no6 6e have used public repository to resolve dependencies. 8ut .or many reasons you may 6ant to set
up your o6n repository
internet access D companies may have internet access or usage policy. #his may limit or even restrict
access to internet. ,etting up a enterprise repository helps to overcome this issue.
reliability/accuracy D modules available in public repository may have ;uality issues.
security D module available in public repository may have security issues and In.ormation ,ecurity
policy o. the company may deny the access to these repository.
De.ault con.iguration o. Ivy allo6s .ollo6ing types o. repository
ublic D repositories available in internet
/ocal D private repository7 access is restricted to the user
,hared D a common repository shared bet6een the members o. a team
!ettings #iles
#ill no6 6e have used de.ault settings o. Ivy to carry out tas%s. ,ettings .iles are :ml .iles usually called
ivysettings.:ml and they are used to override de.ault settings.
De.ault settings are de.ined by Ivy in its o6n ivysettings.:ml 6hich is pac%aged in ivy.5ar.
$atterns
attern is used by Ivy in many tas%s and settings. Ivy places the arti.acts in the .ilesystem but it doesn<t
stipulates a particular directory structure. attern is used to de.ine a directory structure or the arti.act .ile
name. Ivy uses patterns to
to name arti.acts
to place arti.acts in proper directory
to access or search arti.acts in repositories
attern is composed o. to%ens. #hese to%ens are replaced by actual values to evaluate a particular module or
arti.act. #o%en are surrounded by s;uare brac%ets as Ke:tL.
Important to%ens
KorganisationL organisation name
KmoduleL module name
KrevisionL revision name
Karti.actL arti.act name Mor idN
KtypeL arti.act type
Ke:tL arti.act .ile e:tension
Kcon.L con.iguration name
Ivy - Beginners Guide
Ivy ore once"ts $2
1e can mi: to%ens7 Ivy variables and actual directory names to compose a pattern.
-or e:ample 6e 6ant to install or add module developed by :y9.com to our local repository. Module igo
has three arti.acts = class 5ar7 source 5ar and 5avadoc 5ar. Jalues .or to%en 6ill be
Token %alue
KorganisationL com.:y9
KmoduleL pigo
KrevisionL 1.1
Karti.actL pigoapp
KtypeL 5ar D .or class 5ar .ile
source D .or the source 5ar .ile
doc D .or 5avadoc 5ar .ile
Ke:tL 5ar
Kcon.L de.ault D 6e are using the de.ault
con.iguration o. the Ivy
-or to%en KtypeL value changes depending on the arti.act and .or all other to%ens values are same .or all three
arti.acts.
>o6 6e can use patterns to control the directory structure and arti.act naming as
7organisation8/7-od/le8/7type8s/7artifact8-7revision8.7ext8
#his pattern ma%es Ivy to
create a directory 6ith organisation name
under that create a directory 6ith module name
under that create three directories .or ! types D 5ar7 source and doc. As there is a s a.ter KtypeL
actual directory names 6ill be 5ars7 sources and docs
then place the arti.acts under respective directories. -ile name 6ill have arti.act name and
revision
&esult 6ould be
com.:y9/pigo/5ars/pigoapp=1.1.5ar
com.:y9/pigo/sources/pigoapp=1.1.5ar
com.:y9/pigo/docs/pigoapp=1.1.5ar
7organisation8/7-od/le8/7artifact8-7type8-7revision8.7ext8
#his pattern ma%es Ivy to
create a directory 6ith organisation name
under that create a directory 6ith module name
under that place all three arti.acts. -ile name 6ill have arti.act name7 type and revision
Ivy - Beginners Guide
Ivy ore once"ts $3
&esult 6ould be
com.:y9/pigo/pigoapp=5ar=1.1.5ar
com.:y9/pigo/pigoapp=source=1.1.5ar
com.:y9/pigo/pigoapp=doc=1.1.5ar
/ater 6hile resolving the dependencies Ivy 6ill use this pattern to handle directories and .ile appropriately.
In retrieve tas% in last chapter 6e had given pattern as
-yfolder/7artifact8-7revision8.7ext8
#his pattern ma%es Ivy to
to retrieve re;uired arti.acts and name them 6ith arti.act name7 revision and e:t.
then copy the arti.act to my.older
&esult 6ould be
my.older/pigoapp=1.1.5ar
my.older/pigoapp=1.1.5ar
my.older/pigo/pigoapp=1.1.5ar
"esolvers
0ne o. the con.igurable items in ivysettings.:ml is &esolvers.
&epositories are not homogeneous. It may be hosted on a 6eb server7 local .ilesystem7 v.s .ilesystem7 ssh
server etc. /ayout o. the repositories and naming o. arti.acts di..ers among repositories.
Ivy uses concept called &esolver to contact repository and .etch the .iles. -or this Ivy has to
decide net6or% or .ilesystem protocol to access the repository.
then get hold o. ivy .ile 6hich may .ollo6 di..erent layout/naming in di..erent repositories.
then .ind proper arti.acts 6hich may .ollo6 di..erent layout/naming in di..erent repositories.
&esolver de.ines these aspects so that Ivy can properly resolve the dependencies.
&esolvers de.ines a list o. dependency resolvers usable by Ivy. 2ach dependency resolver is identi.ied by its
name.
Ivy ships 6ith built=in dependency resolvers that handle most common needs. #here are t6o types o.
resolvers
standard D these resolvers are used by Ivy .or actual resolve tas%
composite D these resolvers delegate the 6or% to standard resolvers
/ist o. important 8uilt=in &esolversB
Ivy - Beginners Guide
Ivy ore once"ts $4
Name Type Description
I8iblio ,tandard -inds arti.acts on ibiblio.
-ile,ystem ,tandard #his very per.ormant resolver .inds ivy .iles and arti.acts in your .ile system.
3rl ,tandard -inds ivy .iles and arti.acts in any repository accessible 6ith urls.
Chain Composite Delegates the .inding to a chain o. sub resolvers.
Dual Composite Delegates the .inding o. ivy .iles to one resolver and o. arti.acts to another.
ivysettings.:ml 6ith a url resolver B
ivysettings.xml
,ivysettings0
,resolvers0
,/rl na-e(./rl-exa-ple.0
,ivy pattern(.http+//ivyrep.xyz.co-/7-od/le8/7revision8/ivy-7revision8.x-l. /0
,artifact pattern(.http+//ivyrep.xyz.co-/7-od/le8/7revision8/7artifact8.7ext8. /0
,//rl0
,/resolvers0
,/ivysettings0
#his 6ill loo% .or ivy.:ml and arti.acts based on ivy pattern and arti.act pattern.
&'amples
De.ines a resolver called :y9 using the maven 2 public repository to .ind module metadata Musing maven 2
pomsN and arti.acts.
,resolvers0
,ibiblio na-e(.xyz. -2co-patible(.tr/e. /0
,resolvers0
De.ines a resolver named test using url. #his is e;uivalent to the ibiblio resolver mentioned above.
,resolvers0
,/rl na-e(.test. -2co-patible(.tr/e.0
,artifact pattern(
.http+//repo1.-aven.org/-aven2/7organisation8/7-od/le8/7revision8/
7artifact8-7revision8.7ext8./0
,//rl0
,resolvers0
De.ines a resolver using ibiblio pointing to httpB//repo.pentaho.org/arti.actory/repo instead o. de.ault
httpB//repo1.maven.org/maven2
,resolvers0
,ibiblio na-e(.pentaho. -2co-patible(.tr/e.
root(.http+//repo.pentaho.org/artifactory/repo. /0
,resolvers0
De.ines a local .ilesystem resolver named mylocal. Jariable ivy.de.ault.ivy.user.dir by de.ault points .ivy2
directory in user home directory and 6e are using local directory under that. &epository layout is as per the
rest o. pattern KorganisationL/KmoduleL/KtypeLs/Karti.actL=KrevisionL=KtypeLs.Ke:tL
Ivy - Beginners Guide
Ivy ore once"ts $5
,resolvers0
,filesyste- na-e(.-ylocal.0
,ivy pattern(
.*5ivy.defa/lt.ivy./ser.dir=/local/7organisation8/7-od/le8/7type8s/7artifact8-
7revision8-7type8s.7ext8. /0
,artifact pattern(
.*5ivy.defa/lt.ivy./ser.dir=/local/7organisation8/7-od/le8/7type8s/7artifact8-
7revision8-7type8s.7ext8. /0
,/filesyste-0
,/resolvers0
De.ines a Chain resolver. Chain is a composite resolver 6hich delegates to a chain o. sub resolvers. 1ith this
Ivy 6ill try to resolve through local .ilesystem resolver and on .ailure it 6ill try maven2 public repository.
,settings defa/ltEesolver(.chain-resolver. /0
,resolvers0
,chain na-e(.chain-resolver.0
,filesyste- na-e(.-ylocal.0
,ivy pattern(
.*5ivy.defa/lt.ivy./ser.dir=/local/7organisation8/7-od/le8/type8s/artifact8-
7revision8-7type8s.7ext8. /0
,artifact pattern(
.*5ivy.defa/lt.ivy./ser.dir=/local/7organisation8/7-od/le8/type8s/artifact8-
7revision8-7type8s.7ext8. /0
,/filesyste-0
,ibiblio na-e(.ibiblio. -2co-patible(.tr/e. /0
,/chain0
,/resolvers0
De(ault "esolvers
Ivy ships 6ith a set o. resolvers 6hich 6ill be used in absence o. our o6n resolvers.
Name Type Description
local standard -ilesystem resolver points to A@0M2/.ivy2/local
shared standard -ilesystem resolver points to A@0M2/.ivy2/shared
public standard Ibiblio resolver points httpB//repo1.maven.org/maven2
main composite Chain and Dual resolver to shared and public
de.ault composite Chain resolver to local and main
@ierarchical &elationship is as .ollo6s
de.ault
local
main
shared
public
Ivy by de.ault uses resolver named de.ault 6hich .irst try local and on .ailure try 6ith shared and .inally
public.
1e can chec% this by running resolve tas% a.ter deleting the .ivy2/cache directory and disabling internet
connection o. the machine. -ollo6ing output sho6s that it has tried local7 shared and public in that order
Ivy - Beginners Guide
Ivy ore once"ts $6
>o6 6e have gone through some important concepts in Ivy and 6ith these 6e can start building our o6n
repositories.
Ivy - Beginners Guide
Install Task $7
Chapter Install Task
&esolves a module and its dependencies .rom a repository and install them in another repository. Install
copies module<s ivy .ile and arti.acts .rom source repository to a target repository.
#o build private repository li%e local or shared repository 6e have to copy the module<s .iles .rom public
repository to our private repository.
)ocal "epository
8uilt in Jariable AOivy.de.ault.ivy.user.dirP points to .ivy2 directory in user home. 8y de.ault7 the local
repository location is AOivy.de.ault.ivy.user.dirP/local.
Add .ollo6ing .iles to 6or% dir.
build.xml
,project na-e(.localrepository. defa/lt(.install.
x-lns+ivy(.antlib+org.apache.ivy.ant.0

,target na-e(.install. description(.--0 install -od/les to localreporsitory.0
,ivy+install organisation(.co--ons-lang. -od/le(.co--ons-lang.
revision(.2.D. transitive(.tr/e. overwrite(.false.
fro-(.p/blic. to(.local./0
,/target0
,/project0
#his 6ill install commons=lang 2.' .rom public repository to local .ilesystem repository.
&un ant and install tas% 6ill create a ne6 local directory in A@0M2/.ivy2.
/ist o. .iles in A@0M2/.ivy2/local
1e have not provided any de.inition .or local7 public resolver and pattern to be .ollo6ed by Ivy 6hile
installing the arti.acts in local repository. @o6 come Ivy is able to resolve these aspects. In the output o.
build you 6ill have .ollo6ing line
KivyBresolveL BB loading settings BB url G 5arB.ileB/opt/ant/apache=ant=1.(.2/lib/ivy=.2.*.5arQ
/org/apache/ivy/core/settings/ivysettings.:ml
Ivy - Beginners Guide
Install Task $8
#his gives hint that ivy is using a de.ault ivysettings.:ml pac%aged in ivy=2.*.5ar. 2:tract this archive to get
ivysettings.:ml in org/apache/ivy/core/settings 6ith .ollo6ing contents
/org/apache/ivy/core/settings/ivysettings.xml
,ivysettings0
,settings defa/ltEesolver(.defa/lt./0
,incl/de /rl(.*5ivy.defa/lt.settings.dir=/ivysettings-p/blic.x-l./0
,incl/de /rl(.*5ivy.defa/lt.settings.dir=/ivysettings-shared.x-l./0
,incl/de /rl(.*5ivy.defa/lt.settings.dir=/ivysettings-local.x-l./0
,incl/de /rl(.*5ivy.defa/lt.settings.dir=/ivysettings--ain-chain.x-l./0
,incl/de /rl(.*5ivy.defa/lt.settings.dir=/ivysettings-defa/lt-chain.x-l./0
,/ivysettings0
8y de.ault ivy comes 6ith shared7 de.ault7 local7 public7 main resolvers. -or each o. these it points to
separate settings .ile. In same directory 6e 6ill get these .ive settings .iles.
/org/apache/ivy/core/settings/ivysettings-public.xml
,ivysettings0
,resolvers0
,ibiblio na-e(.p/blic. -2co-patible(.tr/e./0
,/resolvers0
,/ivysettings0
/org/apache/ivy/core/settings/ivysettings-local.xml
,ivysettings0
,property na-e(.ivy.local.defa/lt.root.
val/e(.*5ivy.defa/lt.ivy./ser.dir=/local. override(.false./0
,property na-e(.ivy.local.defa/lt.ivy.pattern.
val/e(.7organisation8/7-od/le8/7revision8/7type8s/7artifact8.7ext8.
override(.false./0
,property na-e(.ivy.local.defa/lt.artifact.pattern.
val/e(.7organisation8/7-od/le8/7revision8/7type8s/7artifact8.7ext8.
override(.false./0
,resolvers0
,filesyste- na-e(.local.0
,ivy pattern(.*5ivy.local.defa/lt.root=/*5ivy.local.defa/lt.ivy.pattern=. /0
,artifact pattern(.*5ivy.local.defa/lt.root=/*ivy.local.defa/lt.artifact.pattern=./0
,/filesyste-0
,/resolvers0
,/ivysettings0
-rom these .iles ivy gets de.inition .or public and local resolvers.
Ivy pattern and arti.act pattern are 7organisation8/7-od/le8/7revision8/7type8s/7artifact8.7ext8.
/ocal repository 6ill be o. this layout.
1e have no6 success.ully created a local repository. It is al6ays a good idea to do a resolve and retrieve the
modules to ensure that all arti.acts are retrieve .rom our repository 6ithout any naming con.licts.
#o do that add ivy.:ml to install directory
ivy.xml
Ivy - Beginners Guide
Install Task $#
,>x-l version(.1.0. encoding(.:3%-88?@-1.>0
,ivy--od/le version(.2.0. x-lns+xsi(.http+//www.wA.org/2001/B&C3che-a-instance.
xsi+no!a-espace3che-aCocation(.http+//ant.apache.org/ivy/sche-as/ivy.xsd.0
,info organisation(.in.ex. -od/le(.si-pleivy. stat/s(.integration.0,/info0
,dependencies0
,dependency org(.co--ons-lang. na-e(.co--ons-lang. rev(.2.D. /0
,/dependencies0
,/ivy--od/le0
#his is the same .ile 6hich 6e had used earlier in resolve tas%.
Add .ollo6ing snippet to build.:ml and run ant resolve
,target na-e(.resolve. description(.resolve dependencies with ivy.0
,ivy+retrieve /0
,/target0
>o6 Ivy 6ill do a resolve and retrieve and place the retrieved arti.acts in lib directory.
As 6e have not provided retrieve pattern in retrieve tas% Ivy as used de.ault retrieve pattern.
>o6 local repository is good to resolve. 8ut i. you observe the output you 6ill have line as .ollo6s
KivyBresolveL con.sB Kde.aultL
KivyBresolveL .ound commons=langRcommons=langS2.' in public
KivyBresolveL BB resolution report BB resolve 1+2ms BB arti.acts dl 2$ms
0utput indicates that commons=lang is .ound in public. De.ault set up is Ivy has .irst loo% in local7 then in
shared and then public. 8ut Ivy is still resolving .rom public repository even though module is in local.
&eason is cache. As e:plained earlier ivy 6ill chec% the cache and resolve. During install ivy has copied the
module to cache and then to local. #hat copy is still in cache. During resolve it 6ill get this copy and says
that it has .ound it in public.
3se cleancache ant tas% to clear the cache. Add .ollo6ing snippet to build.:ml and run ant clean=cache
,target na-e(.clean-cache. description(.--0 clean the cache.0
,ivy+cleancache /0
,/target0
#his tas% 6ill delete the cache directory in .ivy2. 1ith this cache is cleared.
>o6 run resolve tas% and ivy 6ill resolve .rom local repository. 0utput indicates that commons=lang is
.ound in local and triggers a do6nload to cache.
*verriding the de(ault settings
Ivy - Beginners Guide
Install Task 2%
#here are t6o 6ays to override de.ault settings either through setting property in ant target or through
ivysettings.:ml .ile

As an e:ample let us change the layout o. local repository. Change build.:ml as
build.xml
,project na-e(.shared repository. defa/lt(.install.
x-lns+ivy(.antlib+org.apache.ivy.ant.0
,target na-e(.install. description(.local at non defa/lt location. 0
,property na-e(.ivy.local.defa/lt.ivy.pattern.
val/e(.7organisation8/7-od/le8/ivys/ivy-7revision8.x-l. /0
,property na-e(.ivy.local.defa/lt.artifact.pattern.
val/e(.7organisation8/7-od/le8/7type8s/7artifact8-7revision8.7ext8. /0
,ivy+install organisation(.co--ons-lang. -od/le(.co--ons-lang. revision(.2.D.
transitive(.tr/e. overwrite(.false.
fro-(.p/blic. to(.local./0
,/target0
,/project0
1e have used ant property to change ivy pattern and arti.act pattern. Install still uses de.ault local resolver
but layout o. repository is changed as per ne6 pattern.
Alternatively 6e can use ivysettings.:ml to override de.ault settings. -ollo6ing ivysettings.:ml de.ines
resolver named myresolver. It points to A@0M2/.ivy2/local but layout pattern is di..erent .rom de.ault local
resolver. lace this .ile along 6ith build.:ml and Ivy 6ill load this .ile instead o. de.ault .ile that comes 6ith
Ivy. Ivy 6ill get only three resolvers myresolver7 mylocal and mypublic. De.ault resolver de.ault7 main7
local7 shared and public 6ill not be available as de.ault ivysettings.:ml is not loaded. 3se mylocal and
mypublic in install tas% .rom and to attributes.
ivysettings.xml
,ivysettings0
,property na-e(.ivy.local.defa/lt.root.
val/e(.*5ivy.defa/lt.ivy./ser.dir=/local. override(.false. /0
,property na-e(.ivy.local.defa/lt.ivy.pattern.
val/e(.7organisation8/7-od/le8/ivys/ivy-7revision8.x-l. override(.false. /0
,property na-e(.ivy.local.defa/lt.artifact.pattern.
val/e(.7organisation8/7-od/le8/7type8s/7artifact8-7revision8.7ext8.
override(.false. /0
,settings defa/ltEesolver(.-yresolver./0
,resolvers0
,chain na-e(.-yresolver.0
,filesyste- na-e(.-ylocal.0
,ivy pattern(.*5ivy.local.defa/lt.root=/*5ivy.local.defa/lt.ivy.pattern=. /0
,artifact pattern(
.*5ivy.local.defa/lt.root=/*5ivy.local.defa/lt.artifact.pattern=. /0
,/filesyste-0
,ibiblio na-e(.-yp/blic. -2co-patible(.tr/e. /0
,/chain0
,/resolvers0
,/ivysettings0
In ivysettings.:ml 6e have de.ined t6o resolvers
mylocal D .ilesystem based repository 6ith root at .ivy2/local as de.ined by variable
ivy.local.de.ault.root
mypublic D de.ault maven2 public repository
Ivy - Beginners Guide
Install Task 2$
Ivy pattern 7organisation8/7-od/le8/ivys/ivy-7revision8.x-l has placed ivy.:ml in ivys directory.
Arti.act pattern 7organisation8/7-od/le8/7type8s/7artifact8-7revision8.7ext8 has placed 5ar7
source and 5avadoc arti.acts in 5ars7 sources and 5avadocs directory. 2ven though all three arti.acts are named
as commons=lang=2.'.5ar Ivy 6ill distinguishes them by the directory name.
!hared repository
0nly di..erence bet6een local and shared repository is that all users can access a shared repository and
6hereas local repository is private to a user.
De.ault con.iguration comes 6ith a resolver named shared and it point to A@0M2/.ivy2/shared directory.
8ut in case you don<t 6ant a shared repository in your home directory then shared repository can be created
in other locations as .ollo6s.
,hared repository should be in a directory to 6hich all users have read and 6rite access. /et us create a
shared repository at /opt/ivy/repository/shared
-1dir -p /opt/ivy/repository/shared
chown -E ivy.ivy /opt/ivy
ch-od -E GGG /opt/ivy
#his 6ill create a directory accessible by all users.
3se .ollo6ing variables to override the de.ault values o. shared resolver.
ivy.shared.de.ault.root
ivy.shared.de.ault.ivy.pattern
ivy.shared.de.ault.arti.act.pattern
build.xml
,project na-e(.shared repository. defa/lt(.install.
x-lns+ivy(.antlib+org.apache.ivy.ant.0
,target na-e(.install. description(.--0 install -od/les to shared reporsitory. 0
,property na-e(.ivy.shared.defa/lt.root. val/e(./opt/ivy/repository/shared./0
,ivy+install organisation(.co--ons-lang. -od/le(.co--ons-lang. revision(.2.D.
transitive(.tr/e. overwrite(.false.
fro-(.p/blic. to(.shared./0
,/target0
,/project0
>o6 ivy.shared.de.ault.root variable is pointed to /opt/ivy/repository/shared. 1ith this all users can read and
6rite shared repository.
#o access this shared repository users have to override ivy.shared.de.ault.root variable be.ore calling
ivyBresolve in build.:ml
Moving "epository to +eb !erver
,hared repository e:plained in last section can be accessed by all users but they have to be on same machine
Ivy - Beginners Guide
Install Task 22
or access the server through telnet. In enterprise set up7 developers 6or% .rom des%top and repository 6ill be
on a server. -ollo6ing method may be used to set up repository accessible via net6or%.
,hared repository has to be on server 6hich has 6eb server running on it and maintained by a administrator.
Create a directory .or the repository under Document &oot .older o. the httpd.
-1dir /var/www/ht-l/ivyrepo
chown apache.apache /var/www/ht-l/ivyrepo
ch-od GG? /var/www/ht-l/ivyrepo
/ser-od -a< apache - H - is /serna-e
service httpd start H start the apache web server
As e:ample 6e are using Apache http server 6ith its de.ault Document root at /var/666/html. 3sers 6ho
are allo6ed to install modules are added to apache group. #hese users have to use .ollo6ing build.:ml to
install the modules.
build.xml
,project na-e(.shared repository. defa/lt(.install.
x-lns+ivy(.antlib+org.apache.ivy.ant.0
,target na-e(.install. description(.--0 install -od/les to shared reporsitory. 0
,property na-e(.ivy.shared.defa/lt.root. val/e(./var/www/ht-l/ivyrepo./0
,ivy+install organisation(.co--ons-lang. -od/le(.co--ons-lang. revision(.2.D.
transitive(.tr/e. overwrite(.false.
fro-(.p/blic. to(.shared./0
,/target0
,/project0
Developers have to use .ollo6ing ivysettings.:ml to access the repository .rom their des%tops.
ivysettings.xml
,ivysettings0
,property na-e(.web.ivy.pattern.
val/e(.7organisation8/7-od/le8/7revision8/7type8s/7artifact8.7ext8.
override(.false. /0
,property na-e(.web.artifact.pattern.
val/e(.7organisation8/7-od/le8/7revision8/7type8s/7artifact8.7ext8.
override(.false. /0
,settings defa/ltEesolver(.chain. /0
,resolvers0
,chain na-e(.chain.0
,/rl na-e(.web.0
,ivy pattern(.http+//localhost/ivyrepo/*5web.ivy.pattern=. /0
,artifact pattern(.http+//localhost/ivyrepo/*5web.artifact.pattern=. /0
,//rl0
,ibiblio na-e(.p/blic. -2co-patible(.tr/e. /0
,/chain0
,/resolvers0
,/ivysettings0
@ere 6e are using 3&/ resolver. Change httpB//localhost in ivy and arti.act pattern to 3&/ o. the server.
"epository Manager
1eb based &epository manager li%e Archiva7 Arti.actory or >e:us may be used to maintain the repository.
#hese .ront ends has a security model .or the repository access and group o. users can upload the modules to
repository through them.
Ivy - Beginners Guide
&u'lis! task 23
Chapter ! "u#lish task
ublish tas% publishes module<s arti.acts and resolved descriptor to a repository. #his tas% is used to publish
the modules developed by us or modules 6hich are not available in other repositories.
#his tas% 6ill not create the arti.acts. Arti.acts are created separately by the build system.
#o publish a module 6e re;uire arti.acts and descriptor .ile ivy.:ml. In actual pro5ect 6e use ant to build the
pro5ect and create 5ar .or module7 source and 5avadoc etc.
-or demonstration o. publish tas%7 instead o. actual arti.act7 let use 9ero byte .iles as three dummy arti.acts
to/ch si-pleivy-jar.jar si-pleivy-javadoc.jar si-pleivy-so/rce.jar
#his 6ill create three 9ero byte .iles.
>o6 add ivy.:ml
ivy.xml
,ivy--od/le version(.2.0.0
,info organisation(.co-.xyz. -od/le(.si-pleivy. /0
,p/blications0
,artifact na-e(.si-pleivy. type(.jar. ext(.jar./0
,artifact na-e(.si-pleivy. type(.javadoc. ext(.jar./0
,artifact na-e(.si-pleivy. type(.so/rce. ext(.jar./0
,/p/blications0
,dependencies0
,dependency org(.co--ons-lang. na-e(.co--ons-lang. rev(.2.D. /0
,/dependencies0
,/ivy--od/le0
#his 6ill be the descriptor .or our module simpleivy. 1e have indicated in publications element that this
publication has three arti.acts 6ith their types and e:t.
>o6 add build.:ml 6ith publish tas%
build.xml
,project na-e(.localrepository. defa/lt(.p/blish.
x-lns+ivy(.antlib+org.apache.ivy.ant.0
,target na-e(.p/blish. description(.)/blish this b/ild into repository.0
,ivy+resolve/0
,ivy+p/blish p/brevision(.1.0. stat/s(.release. resolver(.local.
overwrite(.tr/e. 0
,artifacts pattern(.7artifact8-7type8.7ext8./0
,/ivy+p/blish0
,/target0
,/project0
Ivy - Beginners Guide
&u'lis! task 24
In publish tas% 6e have given
pubrevision D publication revision. 1.*
status D ,tatus o. revision. Ivy allo6s integration7 milestone and release as status
resolver D 6e 6ant to publish the module to local repository
arti.acts pattern D this pattern 6ill be used by ivy to search .or arti.acts. 0ur arti.acts has simple
pattern = Karti.actL=KtypeL.Ke:tL li%e simpleivy=5avadoc.5ar. #his pattern is used only to search .or
arti.acts de.ined in ivy.:ml. It is important to note that 6hile placing the arti.acts in repository Ivy
6ill use the pattern provided in resolver de.inition .or layout and name the arti.acts.
>o6 6e are ready to publish our simpleivy module to local repository. &un ant and it 6ill publish our
modules to local repository as seen .rom .ollo6ing output.
KivyBpublishL BB publishing BB com.:y9Rsimpleivy
KivyBpublishL published simpleivy to /home/m/.ivy2/local/com.:y9/simpleivy/1.*/5ars/simpleivy.5ar
KivyBpublishL published simpleivy to /home/m/.ivy2/local/com.:y9/simpleivy/1.*/5avadocs/simpleivy.5ar
KivyBpublishL published simpleivy to /home/m/.ivy2/local/com.:y9/simpleivy/1.*/sources/simpleivy.5ar
KivyBpublishL published ivy to /home/m/.ivy2/local/com.:y9/simpleivy/1.*/ivys/ivy.:ml
Ivy has used pattern given de.ault local resolver de.inition in /org/apache/ivy/core/settings/ivysettings=
local.:ml to place the .iles in repository.
7organisation8/7-od/le8/7revision8/7type8s/7artifact8.7ext8 to place ivy.x-l
7organisation8/7-od/le8/7revision8/7type8s/7artifact8.7ext8 to place artifacts
0ne more thing to observe is that no6 you 6ill have t6o ivy .ile in your 6or% directory.
0rginal ivy.:ml 6hich you had given
,econd ivy=ivy.:ml generated by publish
#his second ivy=ivy.:ml .ile is resolved descriptor 6hich is also %no6n as delivered ivy .ile. 1hen 6e
invo%ed publish tas% .irst it run deliver tas%. Deliver tas% generates a resolved descriptor o. the module7
based upon the last resolve done. #he resolved ivy .ile contains updated in.ormation about the delivered
module7 such as revision and status. And this second .ile is actually published to repository.
Ivy - Beginners Guide
Ivy() 25
Part II IvyDE
#his part cover
installation o. Ivy and IvyD2 plugins
build a eclipse pro5ect 6ith Ivy
e:plore IvyD2 .eatures
Ivy - Beginners Guide
Installation 26
Chapter 1$ Installation
,pdate !ite
,elect 2clipse Install >e6 ,o.t6are option and add7 6or%6ith .ollo6ing update site
httpB//666.apache.org/dist/ant/ivyde/updatesite/
It 6ill display plugins available .or installation
Apache Ivy library
Apache IvyD2 2clipse plugin
select both and proceed to install. #his 6ill install ivy7 ivy ant tas%s and ivyide
Manual installation
#his method involves installation o. IvyD2 and Ivy plugins.
IvyD2 lugin
#his plugin lin%s core Ivy to 2clipse. Do6nload the IvyD2 plugin .rom
httpB//ant.apache.org/ivy/ivyde/do6nload.cgi. -or 2clipse Indigo do6nload apache=ivyde=
2.1.*.2*1**(1*1(*+=&2/2A,2.tar.g9 and uncompress to get t6o .olders containing the arti.acts to deploy
in your 2clipse. Copy them to eclipse installation directory as .ollo6sB
plugins/org.apache.ivyde.eclipse?2.1.*.2*1**(1*1(*+=&2/2A,2.5ar to A2C/I,2?@0M2/plugins
.eatures/org.apache.ivyde..eature?2.1.*.2*1**(1*1(*+=&2/2A,2.5ar to A2C/I,2?@0M2/.eatures
Ivy lugin
#his plugin is Ivy and Ant tas%. Get the latest Ivy .eature and plugin .rom .ollo6ing sites
httpB//666.gtlib.gatech.edu/pub/apache//ant/ivyde/updatesite/plugins
httpB//666.gtlib.gatech.edu/pub/apache//ant/ivyde/updatesite/.eatures
-or 2clipse Indigo do6nload and copy them to your eclipse installation directory as .ollo6s
org.apache.ivy?2.2.*..inal?2*1**)2!2!*'2!.5ar to A2C/I,2?@0M2/plugin
org.apache.ivy.eclipse.ant?2.2.*..inal?2*1**)2!2!*'2!.5ar to A2C/I,2?@0M2/plugin
org.apache.ivy..eature?2.2.*..inal?2*1**)2!2!*'2!.5ar to A2C/I,2?@0M2/.eatures
A.ter installation restart 2clipse and menu bar 6ill have &esolve button o. Ivy
Ivy - Beginners Guide
Resolve 27
Chapter 11 Resolve
/ets use IvyD2 to resolve dependencies o. a 4ava ro5ect.
Create a regular 4ava ro5ect in 2clipse named simpleivy. Add class named ,impleIvy
in.ex.ivy.SimpleIvy.java
pac1age in.ex.ivy2
i-port org.apache.co--ons.lang.3tring4tils2
p/blic class 3i-ple:vy 5
p/blic static void -ain63tring78 args9 5
3tring string ( 3tring4tils./pperCase6.:vy with 'clipse.92
3yste-.o/t.println6string92
=
=
As e:pected 2clipse 6ill sho6 errors since 2clipse is unable to .ind commons.lang in pro5ect<s build path.
Instead o. manually adding commons=lang pac%age to build path let us delegate the dependency management
to Ivy. -or this .irst 6e have to add a .ile named ivy.:ml under the root .older .older o. the pro5ect.
Ivy.xml
,>x-l version(.1.0. encoding(.:3%-88?@-1.>0
,ivy--od/le version(.2.0.
x-lns+xsi(.http+//www.wA.org/2001/B&C3che-a-instance.
xsi+no!a-espace3che-aCocation(.http+//ant.apache.org/ivy/sche-as/ivy.xsd.0
,info organisation(.in.ex. -od/le(.si-pleivy. stat/s(.integration.0
,/info0
,dependencies0
,dependency org(.co--ons-lang. na-e(.co--ons-lang. rev(.2.D. /0
,/dependencies0
,/ivy--od/le0
#his is the same ivy.:ml 6e had used in ant tas% earlier. Dependencies element indicates that our pro5ect is
dependent on commons=lang revision 2.'. 1e can also use -ile=F>e6=F0ther=FIvyD2=FIvy -ile 1i9ard to
add ivy.:ml .ile.
>o6 the pro5ect structure loo%s as
>e:t step is add this ivy.:ml to build path o. the pro5ect. -or this right clic% on ivy.:ml and choose Add Ivy
Ivy - Beginners Guide
Resolve 28
/ibrary... .rom the conte:t menu. IvyD2 Managed /ibraries 6indo6 is displayed
In in Main tab7 Ivy -ile is set as ivy.:ml 6hich 6e added to root .older o. the pro5ect. /eave the
Con.igurations to de.ault.
-or the moment lets not bother about other tabs = ,ettings7 &etrieve and Advanced 6hich 6e shall use in later
chapters.
Clic% on -inish. #his 6ill add libraries to 2clipse build path. 8ut these libraries are special in the sense that
they are managed by IvyD2. Internally IvyD2 6ill use Ivy to get list dependencies mentioned in ivy.:ml and
add them to 2clipse 8uild ath
As soon as you clic% the -inish button Ivy goes into 5ob o. resolving the dependencies you mentioned in
ivy.:ml. It 6ill chec% 6hether &ev 2.' is in cache else it 6ill .etch .rom public. rogress 8ar indicates the
progress o. Ivy resolve 5ob
2rrors in the pro5ect are removed once resolve is over as commons=lang is added to build path o. pro5ect by
IvyD2.
1e can add more dependency lines in ivy.:ml depending on pro5ects re;uirement. Ivy 6ill .etch and IvyD2
6ill add them to the pro5ect build path.
/et us e:plore the pro5ect build path to %no6 6hat IvyD2 has done. &ight clic% on the pro5ect and choose
8uild ath =F Con.igure 8uild ath to 4ava 8uild ath 6indo6. ,elect /ibraries tab and it 6ill sho6 t6o
libraries ivy.:ml and 4&2 ,ystem /ibrary. 2:pand ivy.:ml entry and then commons=lang=2.'.5ar to get the
library details
Ivy - Beginners Guide
Resolve 2#
As 6e can see IvyD2 has lin%ed source and 5avadoc automatically. All dependencies mentioned in ivy.:ml
6ill be added under ivy.:ml KTL
Ivy - Beginners Guide
Retrieve 3%
Chapter 12 Retrieve
&etrieve 6ill copy the dependencies to the pro5ect directory. #his is done a.ter Ivy completes the &esolve
step.
In IvyD2 6e can enable retrieve at t6o level either at 6or%space level or at pro5ect level.
&nable "etrieve (or all pro-ects in +orkspace
Go to 1indo6 =F re.erences =F Ivy =F &etrieve
Ma%e changes as .ollo6s and save settings
@ere 6e are indicating that
IvyD2 has to retrieve a.ter
resolve.
&etrieve pattern lib/Karti.actL=
KtypeL.Ke:tL indicates that
retrieved modules are to be
placed in lib directory
IvyD2 has to delete stale
arti.acts 6hich are no longer in
dependencies list and lying in
lib directory.
#ypes = 5ar means 6e 6ant only
actual library 5ar .iles and not
5avadoc7 source 5ar etc.
Multiple comma separated
types are allo6ed.
&e.resh the pro5ect 6ith -$. /ib directory is created in root .older o. the pro5ect and dependent 5ar commons=
lang=5ar.5ar is copied to lib/de.ault directory.
&nable "etrieve at pro-ect level
Ivy - Beginners Guide
Retrieve 3$
1or%space level &etrieve settings 6hich 6e had enabled in previous section can be overridden at pro5ect
level.
&ight clic% on pro5ect<s ivy.:ml and choose Add Ivy /ibrary... in the conte:t menu to get Ivy Managed
/ibraries 6indo6. ,elect &etrieve tab.
Ma%e changes as detailed here. @ere 6e have
added KrevisionL to retrieve pattern. ,ave7
&esolve and &e.resh. In lib/de.ault directory
commons=lang=5ar.5ar is no6 changed as
commons=lang=2.'=5ar.5ar as 6e changed the
retrieve pattern .or this pro5ect.
#his setting 6ill be speci.ic to this pro5ect alone.
0ther pro5ect 6ill ta%e 6or%space level settings.
Ivy - Beginners Guide
*t!er Ta's o+ Ivy() ,anaged -i'raries 32
Chapter 13 %ther Ta#s o& Ivy'( )anaged *i#raries
!ettings Tab
In chapter ( 6e had de.ined a resolver named 6eb through ivysettings.:ml to access the repository through
6eb server. 1e can override the de.ault settings 6ith our o6n ivysettings.:ml in this tab.
#his can be either done at 6or%space level or at pro5ect level as e:plained in last chapter. lace the
ivysettings.:ml in root .older o. 6or%space .or 6or%space level or in root .older o. pro5ect to override at
pro5ect level.
Advanced Tab
#his tab is used to
de.ine accepted types
de.ine source types and su..i:es
de.ines 5avadoc types and su..i:es
change ordering o. classpath entries
Again these things can be set at 6or%space level or at pro5ect level.
Ivy - Beginners Guide
Going +urt!er 33
Chapter 14 +oing &urther
>o6 that 6e have covered essential o. Ivy7 readers should be able to 6or% 6ith Ivy and IvyD2 e..ectively.
8ut it doesn<t end there. Ivy comes comes 6ith many advanced .eatures to meet the rigorous needs o. an
enterprise dependency management system. 8elo6 are some o. the pointers 6here readers can gain .urther
insight into .eatures o. Ivy to help them to convert their build system into a pro.essional one.
Tutorials
0..icial documentation is in doc directory o. the ivy distribution. It contains set o. tutorials 6hich e:plains
some o. the .eatures o. Ivy. #hese tutorials 6al% through the e:amples that provided in src/e:ample directory
o. distribution
Ivy Module on(iguration
#hroughout this guide 6e used de.ault con.. Ivy provides a concept called Module Con.igurations. It is a
po6er.ul .eature in Ivy 6hich groups a set o. arti.acts and gives meaning to it. #utorial D 3sing Ivy Module
Con.igurations e:plains this concept o. Ivy.
"e(erence Documentation
0..icial documentation also contains detailed &e.erence documentation 6hich covers .ollo6ing areas o. Ivy
,etting -iles D de.ines the structure o. ivysettings.:ml and tags that are allo6ed in this .iles
Ivy -iles = de.ines the structure o. ivy.:ml and tags that are allo6ed in this .iles
Ant #as%s D provides re.erence about the various Ivy Ant tas%s.
Ivy - Beginners Guide

También podría gustarte