apache ivy beginners guide
TRANSCRIPT
-
8/11/2019 Apache Ivy Beginners Guide
1/33
Ivy - Beginners Guide
ContentsChapter 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! Deault &esolvers...................................................................................................1$
Chapter ( Install #as%..................................................................................................................1+
ocal &epository....................................................................................................1+ 0verriding the deault settings...............................................................................1) ,hared repository....................................................................................................21 Moving &epository to eb ,erver.........................................................................21 &epository Manager...............................................................................................22
Chapter ) ublish tas%.................................................................................................................2! art II IvyD.........................................................................................................................2$
Chapter 1* Installation.................................................................................................................2' 3pdate ,ite.............................................................................................................2' Manual installation.................................................................................................2'
Chapter 11 &esolve......................................................................................................................2+
Chapter 12 &etrieve.....................................................................................................................!*Chapter 1! 0ther #abs o IvyD Managed ibraries..................................................................!2
,ettings #ab............................................................................................................!2 Advanced #ab.........................................................................................................!2
Chapter 1" Going urther.............................................................................................................!!
-
8/11/2019 Apache Ivy Beginners Guide
2/33
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 libraries7dependency can be managed by adding these 5ars to the pro5ect manually. 8ut as pro5ect becomes moresophisticated they may end up 6ith do9ens o e:ternal 5ars. hen pro5ect is developed by a team thenmembers may add these 5ars to pro5ect independently and may lead to bro%en builds. In all these situationsdependency management becomes ;uite cumbersome.
Apache Maven is most popular build manager or 4ava pro5ects 6hich combines build manager anddependency manager. Maven also comes 6ith other eatures li%e pro5ect inormation to handle the completebuild process o 4ava pro5ects. 8ut or some reason you don
-
8/11/2019 Apache Ivy Beginners Guide
3/33
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
-
8/11/2019 Apache Ivy Beginners Guide
4/33
Installation 4
Chapter 2 Installation
e 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. e are installing ant at /opt/ant7 but any other location isine. Ad5ust settings accordingly. Do6nload latest Ivy and Ant rom Apache site.
tar -C /opt/ant/ -xzvf apache-ant-1.8.2-bin.tar.gztar -xzvf apache-ivy-2.2.0-bin-with-deps.tar.gzcp apache-ivy-2.2.0/ivy-2.2.0.jar /opt/ant/apache-ant-1.8.2/libexport !"#$%&'(/opt/ant/apache-ant-1.8.2export )"$(*)"$+*!"#$%&'/bin
A>#?0M and A# has to be set to run ant. :ports may be moved to .bash?proile in inu: so that
they are al6ays set.
Test the installation
#hroughout this guide a 6or% directory li%e 0M/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 to6or%dir and run rom 6or% dir etc. 6hich simply means 6or% rom some directory. -or each e:ercise start6ith a clean directory to avoid any errors and ensuing conusion.
>o6 to test the installation add ollo6ing build.:ml ile to 6or% dir
build.xml,project nae(test ivy defalt(test
xlns+ivy(antlib+org.apache.ivy.ant
,target nae(test description("est ivy installation,ivy+settings /
,/target,/project
and run ant
ant
,uccessul 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>#?0M not set properly
ivy.5ar is missing rom A>#?0M/lib
Ivy - Beginners Guide
-
8/11/2019 Apache Ivy Beginners Guide
5/33
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 sot6are. :ampleBorg.apache etc.
Module Module is a sel=contained7 reusable unit o sot6are. Module typically hasversion. :ampleB commons=lang7 log"5 etc.
Module Descriptor ml ile containing the description or metadata o a module. 3sually this ileis named as ivy.:ml
Artiact Artiact 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
artiacts.4ar7 ,ource 5ar and 4avadoc 5ar are e:amples o artiact.
#ype #ype denotes category o artiact. :ampleB 5ar7 src7 source7 doc7 bundle etc.
Artiact ile name :tension :tension o an artiact. :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 deines 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 artiacts.&epository can be public7 local or shared.
Ivy ,ettings Ivy 6or%s 6ithout any speciic coniguration through deault settings. 8utdeault settings can be overridden through :ml based settings ile. 3suallythis 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 resolveddependencies in ivy cache.
Cachepath Constructs an ant path consisting o artiacts in ivy cache 6hich can bereerred in other ant tas%s through Ant path mechanism.
&etrieve Copies the resolved dependencies rom cache to a speciied directory
Install Installs a module to a speciied repository. In this guide Install tas% is used toinstall libraries rom public repository to a local/shared repository
ublish ublish a module to a repository.
Ivy - Beginners Guide
-
8/11/2019 Apache Ivy Beginners Guide
6/33
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
dir -p src/in/ex/ivy
Add ollo6ing 5ava ile to this dir.
Example.javapacage in.ex.ivy
iport org.apache.coons.lang.3tring4tils
pblic class 'xaple 5 pblic static void ain63tring7 args9 5 3tring string ( 3tring4tils.pperCase6:vy ;eginner xl version(1.0 encoding(:3%-88?@-1>,ivy-odle version(2.0 xlns+xsi(http+//www.wA.org/2001/B&3chea-instance xsi+no!aespace3cheaocation(http+//ant.apache.org/ivy/scheas/ivy.xsd
,info organisation(in.ex odle(ivy-exaple stats(integration ,/info
,dependencies ,dependency org(coons-lang nae(coons-lang rev(2.D / ,/dependencies,/ivy-odle
ivy.:ml provides details about our pro5ect and dependencies. Ivy 6ill read this ile and manage thedependencies.
#his ile has ! sections
1. ivy=module B this is standard root element 6ith version7schema etc.
2. ino B this section is inormation about our pro5ect.
organisation B organisation or company.
module B name o the pro5ect
status B release status milestone7 integration or release.
Ivy - Beginners Guide
-
8/11/2019 Apache Ivy Beginners Guide
7/33
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
e are indicating that our pro5ect is dependent on commons=lang revision 2.'
Add ant build.:ml to 6or% dir.
build.xml,project nae(ivy exaple defalt(resolve xlns+ivy(antlib+org.apache.ivy.ant
,target nae(resolve description(resolve dependencies with ivy,ivy+resolve /
,/target
,/project
In pro5ect element 6e have added ivy namespace so that 6e can use ivy tas%s. EivyBresolve /F in targetnamed resolve is the resolve tas%. #his 6ill resolve the dependencies described in ivy.:ml and places theresolved dependencies in ivy cache.
>o6 run ant. Ivy goes into 5ob o resolving the dependencies 6e mentioned in ivy.:ml. I you are connectedto 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 successully. Inormation about the &esolve is
provided in last portion o output
con ivy is using deault coniguration
module 0ne module is resolved. As Ivy has do6nloaded this moduled6nlded is one.
artiacts there are ! artiacts 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 6hichdeines location o a repository. Ivy has used the deault resolvers. Deault public resolver points tohttpB//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 orgHlog"5H nameHlog"5H revH1.2.1'H/F 6ill do6nload log"5 plus ourdependent modules. -or some reason you don
-
8/11/2019 Apache Ivy Beginners Guide
8/33
Resolve Task 8
transitivealse to dependency line.
Dependency line
#he dependency line Edependency orgHcommons=langH nameHcommons=langH revH2.'H /F in ivy.:mlre;uires couple o e:planations.
o6 to construct this line. Jisit httpB//mvnrepository.com/ and search or module. -or e:ample a search orcommons=lang 6ill yield all matching commons module. ,elect commons=lang among them. Jersionavailable 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 buildsystems li%e maven7 grape etc. ,elect Ivy tab and there you 6ill have the e:act dependency line as re;uiredor Ivy. Cut and paste this line to ivy.:ml
Another thing about this particular dependency line is that organisation is mentioned as commons=lang 6hereas 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%ingassumption about the org or name it is better to search or the module in maven repository and copy thedependency line as provided there.
Ivy ache
0n irst run resolve 6ill etch the artiacts rom a repository and place them in cache. ,ubse;uent call toresolve either rom this pro5ect or another pro5ect or the resolved artiact7 resolve tas% inishes 6ithout anydelay. #hese is because Ivy inds dependencies in cache.
8y deault ivy cache is at 0M/.ivy2. 8eyond that 6e need not bother much about the cache.
Ivy - Beginners Guide
-
8/11/2019 Apache Ivy Beginners Guide
9/33
ac!e"at! Task #
Chapter 5 Cachepath Task
Constructs an ant path consisting o artiacts in ivy cache.
In last chapter 6e used &esolve tas% to resolve and put the artiacts into cache. >o6 to compile the program6e re;uire classpath reerence to these artiacts. Cachepath tas% constructs the ant path or this.
Change build.:ml as ollo6s
build.xml,project nae(ivy exaple defalt(resolve xlns+ivy(antlib+org.apache.ivy.ant
,target nae(resolve description(resolve dependencies with ivy,ivy+resolve /
,ivy+cachepath pathid(defalt.classpath/,/target
,target nae(copile depends(resolve description(Copile,dir dir(bild/classes /,javac srcdir(src destdir(bild/classes
,classpath refid(defalt.classpath /,/javac
,/target,/project
Ater resolve ivy constructs Ant path named deault.classpath. #his path points to resolved artiacts in cache.ater in 5avac tas% 6e have reerred it 6ith reid. In this e:ample 5avac 6ill use the resolved artiacts incache to compile the :ample.5ava
In case ivyBcachepath is called directly 6ithout a ivyBresolve then resolve is internally called beoreconstructing the path.
>ote It is to be noted that artiacts are not copied rom cache either by &esolve or by Cachepath tas%.Cachepath constructs a path points to artiacts in cache.
Ivy - Beginners Guide
-
8/11/2019 Apache Ivy Beginners Guide
10/33
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 speciied location in ilesystem. 0nce dependencies areproperly copied to pro5ect 6or%space use standard ant path creation to build the pro5ect.
Change the build.:ml as ollo6s
build.xml,project nae(ivy exaple defalt(resolve xlns+ivy(antlib+org.apache.ivy.ant
,target nae(resolve description(Eesolve and Eetrieve with ivy
,ivy+resolve /,ivy+retrieve sync(tre type(jar /
,/target,/project
Ater resolve ivy 6ill copy the resolved artiacts rom cache to a ne6ly created lib directory.
In case ivyBretrieve is called directly 6ithout a ivyBresolve then resolve is internally called beore retrievingthe artiacts.
Important attributes that are used in this tas% are
!yncset to true 6ill ensure that any e:tra iles in lib directory is deleted.Type set to 5ar tells ivy to copy only 5ar artiacts. ,ource and 5avadoc artiacts are ignored.
3se pattern attribute to change location 6here retrieved iles are to be placed
,ivy+retrieve sync(tre type(jar pattern(yfolder/7artifact-7revision.7ext /
#his 6ill retrieve the artiacts to myolder directory. 0ther aspects o the pattern 6ill be e:plained later.
,ome modules li%e log"5 use bundleas type or 5ar artiact. 3se ollo6ing line to handle that variation
,ivy+retrieve sync(tre type(jarFbndle /
Ivy - Beginners Guide
-
8/11/2019 Apache Ivy Beginners Guide
11/33
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 setup your o6n repository
internet access companies may have internet access or usage policy. #his may limit or even restrictaccess to internet. ,etting up a enterprise repository helps to overcome this issue.
reliability/accuracy modules available in public repository may have ;uality issues.
security module available in public repository may have security issues and Inormation ,ecuritypolicy o the company may deny the access to these repository.
Deault coniguration o Ivy allo6s ollo6ing types o repository
ublic repositories available in internet
ocal private repository7 access is restricted to the user
,hared a common repository shared bet6een the members o a team
!ettings #iles
#ill no6 6e have used deault settings o Ivy to carry out tas%s. ,ettings iles are :ml iles usually calledivysettings.:ml and they are used to override deault settings.
Deault settings are deined 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 artiacts in the ilesystem but it doesn
-
8/11/2019 Apache Ivy Beginners Guide
12/33
Ivy ore once"ts $2
e 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 igohas three artiacts = class 5ar7 source 5ar and 5avadoc 5ar. Jalues or to%en 6ill be
Token %alue
KorganisationL com.:y9
KmoduleL pigo
KrevisionL 1.1
KartiactL pigoapp
KtypeL 5ar or class 5ar ilesource or the source 5ar iledoc or 5avadoc 5ar ile
Ke:tL 5ar
KconL deault 6e are using the deaultconiguration o the Ivy
-or to%en KtypeL value changes depending on the artiact and or all other to%ens values are same or all threeartiacts.
>o6 6e can use patterns to control the directory structure and artiact naming as
7organisation/7odle/7types/7artifact-7revision.7ext
#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 5ar7 source and doc. As there is a s ater KtypeLactual directory names 6ill be 5ars7 sources and docs
then place the artiacts under respective directories. -ile name 6ill have artiact name andrevision
&esult 6ould be
com.:y9/pigo/5ars/pigoapp=1.1.5arcom.:y9/pigo/sources/pigoapp=1.1.5arcom.:y9/pigo/docs/pigoapp=1.1.5ar
7organisation/7odle/7artifact-7type-7revision.7ext
#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 artiacts. -ile name 6ill have artiact name7 type and revision
Ivy - Beginners Guide
-
8/11/2019 Apache Ivy Beginners Guide
13/33
Ivy ore once"ts $3
&esult 6ould be
com.:y9/pigo/pigoapp=5ar=1.1.5arcom.:y9/pigo/pigoapp=source=1.1.5arcom.: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/7artifact-7revision.7ext
#his pattern ma%es Ivy to
to retrieve re;uired artiacts and name them 6ith artiact name7 revision and e:t.
then copy the artiact to myolder
&esult 6ould be
myolder/pigoapp=1.1.5armyolder/pigoapp=1.1.5armyolder/pigo/pigoapp=1.1.5ar
"esolvers
0ne o the conigurable items in ivysettings.:ml is &esolvers.
&epositories are not homogeneous. It may be hosted on a 6eb server7 local ilesystem7 vs ilesystem7 ssh
server etc. ayout o the repositories and naming o artiacts diers 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 dierent layout/naming in dierent repositories.
then ind proper artiacts 6hich may ollo6 dierent layout/naming in dierent repositories.
&esolver deines these aspects so that Ivy can properly resolve the dependencies.
&esolvers deines a list o dependency resolvers usable by Ivy. ach dependency resolver is identiied by itsname.
Ivy ships 6ith built=in dependency resolvers that handle most common needs. #here are t6o types oresolvers
standard these resolvers are used by Ivy or actual resolve tas%
composite these resolvers delegate the 6or% to standard resolvers
ist o important 8uilt=in &esolversB
Ivy - Beginners Guide
-
8/11/2019 Apache Ivy Beginners Guide
14/33
Ivy ore once"ts $4
Name Type Description
I8iblio ,tandard -inds artiacts on ibiblio.
-ile,ystem ,tandard #his very perormant resolver inds ivy iles and artiacts in your ile system.
3rl ,tandard -inds ivy iles and artiacts 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 artiacts to another.
ivysettings.:ml 6ith a url resolver B
ivysettings.xml,ivysettings ,resolvers ,rl nae(rl-exaple
,ivy pattern(http+//ivyrep.xyz.co/7odle/7revision/ivy-7revision.xl /,artifact pattern(http+//ivyrep.xyz.co/7odle/7revision/7artifact.7ext /
,/rl ,/resolvers,/ivysettings
#his 6ill loo% or ivy.:ml and artiacts based on ivy pattern and artiact pattern.
&'amples
Deines a resolver called :y9 using the maven 2 public repository to ind module metadata using maven 2pomsN and artiacts.
,resolvers,ibiblio nae(xyz 2copatible(tre /
,resolvers
Deines a resolver named test using url. #his is e;uivalent to the ibiblio resolver mentioned above.
,resolvers ,rl nae(test 2copatible(tre ,artifact pattern( http+//repo1.aven.org/aven2/7organisation/7odle/7revision/7artifact-7revision.7ext/ ,/rl,resolvers
Deines a resolver using ibiblio pointing to httpB//repo.pentaho.org/artiactory/repo instead o deaulthttpB//repo1.maven.org/maven2
,resolvers ,ibiblio nae(pentaho 2copatible(tre
root(http+//repo.pentaho.org/artifactory/repo /,resolvers
Deines a local ilesystem resolver named mylocal. Jariable ivy.deault.ivy.user.dir by deault points .ivy2directory in user home directory and 6e are using local directory under that. &epository layout is as per therest o pattern KorganisationL/KmoduleL/KtypeLs/KartiactL=KrevisionL=KtypeLs.Ke:tL
Ivy - Beginners Guide
-
8/11/2019 Apache Ivy Beginners Guide
15/33
Ivy ore once"ts $5
,resolvers ,filesyste nae(ylocal ,ivy pattern( *5ivy.defalt.ivy.ser.dir=/local/7organisation/7odle/7types/7artifact-7revision-7types.7ext / ,artifact pattern(
*5ivy.defalt.ivy.ser.dir=/local/7organisation/7odle/7types/7artifact-7revision-7types.7ext / ,/filesyste,/resolvers
Deines a Chain resolver. Chain is a composite resolver 6hich delegates to a chain o sub resolvers. ith thisIvy 6ill try to resolve through local ilesystem resolver and on ailure it 6ill try maven2 public repository.
,settings defaltEesolver(chain-resolver /,resolvers ,chain nae(chain-resolver
,filesyste nae(ylocal ,ivy pattern( *5ivy.defalt.ivy.ser.dir=/local/7organisation/7odle/types/artifact-
7revision-7types.7ext / ,artifact pattern( *5ivy.defalt.ivy.ser.dir=/local/7organisation/7odle/types/artifact-7revision-7types.7ext / ,/filesyste ,ibiblio nae(ibiblio 2copatible(tre / ,/chain,/resolvers
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 0M/.ivy2/local
shared standard -ilesystem resolver points to 0M/.ivy2/shared
public standard Ibiblio resolver points httpB//repo1.maven.org/maven2
main composite Chain and Dual resolver to shared and public
deault composite Chain resolver to local and main
ierarchical &elationship is as ollo6s
deault
local
main
shared
public
Ivy by deault uses resolver named deault 6hich irst try local and on ailure try 6ith shared and inallypublic.
e can chec% this by running resolve tas% ater 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
-
8/11/2019 Apache Ivy Beginners Guide
16/33
Ivy ore once"ts $6
>o6 6e have gone through some important concepts in Ivy and 6ith these 6e can start building our o6nrepositories.
Ivy - Beginners Guide
-
8/11/2019 Apache Ivy Beginners Guide
17/33
Install Task $7
Chapter Install Task
&esolves a module and its dependencies rom a repository and install them in another repository. Install
copies module
-
8/11/2019 Apache Ivy Beginners Guide
18/33
Install Task $8
#his gives hint that ivy is using a deault ivysettings.:ml pac%aged in ivy=2.*.5ar. :tract this archive to getivysettings.:ml in org/apache/ivy/core/settings 6ith ollo6ing contents
/org/apache/ivy/core/settings/ivysettings.xml,ivysettings ,settings defaltEesolver(defalt/ ,inclde rl(*5ivy.defalt.settings.dir=/ivysettings-pblic.xl/ ,inclde rl(*5ivy.defalt.settings.dir=/ivysettings-shared.xl/ ,inclde rl(*5ivy.defalt.settings.dir=/ivysettings-local.xl/ ,inclde rl(*5ivy.defalt.settings.dir=/ivysettings-ain-chain.xl/ ,inclde rl(*5ivy.defalt.settings.dir=/ivysettings-defalt-chain.xl/,/ivysettings
8y deault ivy comes 6ith shared7 deault7 local7 public7 main resolvers. -or each o these it points toseparate settings ile. In same directory 6e 6ill get these ive settings iles.
/org/apache/ivy/core/settings/ivysettings-public.xml,ivysettings
,resolvers ,ibiblio nae(pblic 2copatible(tre/ ,/resolvers,/ivysettings
/org/apache/ivy/core/settings/ivysettings-local.xml,ivysettings ,property nae(ivy.local.defalt.root
vale(*5ivy.defalt.ivy.ser.dir=/local override(false/ ,property nae(ivy.local.defalt.ivy.pattern
vale(7organisation/7odle/7revision/7types/7artifact.7extoverride(false/
,property nae(ivy.local.defalt.artifact.patternvale(7organisation/7odle/7revision/7types/7artifact.7ext
override(false/ ,resolvers ,filesyste nae(local ,ivy pattern(*5ivy.local.defalt.root=/*5ivy.local.defalt.ivy.pattern= / ,artifact pattern(*5ivy.local.defalt.root=/*ivy.local.defalt.artifact.pattern=/ ,/filesyste ,/resolvers,/ivysettings
-rom these iles ivy gets deinition or public and local resolvers.
Ivy pattern and artiact pattern are7organisation/7odle/7revision/7types/7artifact.7ext.ocal repository 6ill be o this layout.
e have no6 successully created a local repository. It is al6ays a good idea to do a resolve and retrieve themodules to ensure that all artiacts are retrieve rom our repository 6ithout any naming conlicts.
#o do that add ivy.:ml to install directory
ivy.xml
Ivy - Beginners Guide
-
8/11/2019 Apache Ivy Beginners Guide
19/33
Install Task $#
,>xl version(1.0 encoding(:3%-88?@-1>,ivy-odle version(2.0 xlns+xsi(http+//www.wA.org/2001/B&3chea-instance xsi+no!aespace3cheaocation(http+//ant.apache.org/ivy/scheas/ivy.xsd
,info organisation(in.ex odle(sipleivy stats(integration,/info ,dependencies
,dependency org(coons-lang nae(coons-lang rev(2.D / ,/dependencies,/ivy-odle
#his is the same ile 6hich 6e had used earlier in resolve tas%.
Add ollo6ing snippet to build.:ml and run ant resolve
,target nae(resolve description(resolve dependencies with ivy,ivy+retrieve /
,/target
>o6 Ivy 6ill do a resolve and retrieve and place the retrieved artiacts in lib directory.
As 6e have not provided retrieve pattern in retrieve tas% Ivy as used deault retrieve pattern.
>o6 local repository is good to resolve. 8ut i you observe the output you 6ill have line as ollo6s
KivyBresolveL consB KdeaultLKivyBresolveL ound commons=langRcommons=langS2.' in publicKivyBresolveL BB resolution report BB resolve 1+2ms BB artiacts dl 2$ms
0utput indicates that commons=lang is ound in public. Deault set up is Ivy has irst loo% in local7 then inshared 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 themodule to cache and then to local. #hat copy is still in cache. During resolve it 6ill get this copy and saysthat 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 nae(clean-cache description(-- clean the cache ,ivy+cleancache /,/target
#his tas% 6ill delete the cache directory in .ivy2. ith this cache is cleared.
>o6 run resolve tas% and ivy 6ill resolve rom local repository. 0utput indicates that commons=lang isound in local and triggers a do6nload to cache.
*verriding the de(ault settings
Ivy - Beginners Guide
-
8/11/2019 Apache Ivy Beginners Guide
20/33
Install Task 2%
#here are t6o 6ays to override deault settings either through setting property in ant target or throughivysettings.:ml ileAs an e:ample let us change the layout o local repository. Change build.:ml as
build.xml,project nae(shared repository defalt(install xlns+ivy(antlib+org.apache.ivy.ant
,target nae(install description(local at non defalt location
,property nae(ivy.local.defalt.ivy.pattern vale(7organisation/7odle/ivys/ivy-7revision.xl / ,property nae(ivy.local.defalt.artifact.pattern vale(7organisation/7odle/7types/7artifact-7revision.7ext / ,ivy+install organisation(coons-lang odle(coons-lang revision(2.D transitive(tre overwrite(false
fro(pblic to(local/ ,/target,/project
e have used ant property to change ivy pattern and artiact pattern. Install still uses deault local resolverbut layout o repository is changed as per ne6 pattern.
Alternatively 6e can use ivysettings.:ml to override deault settings. -ollo6ing ivysettings.:ml deinesresolver named myresolver. It points to 0M/.ivy2/local but layout pattern is dierent rom deault localresolver. lace this ile along 6ith build.:ml and Ivy 6ill load this ile instead o deault ile that comes 6ithIvy. Ivy 6ill get only three resolvers myresolver7 mylocal and mypublic. Deault resolver deault7 main7local7 shared and public 6ill not be available as deault ivysettings.:ml is not loaded. 3se mylocal andmypublic in install tas% rom and to attributes.
ivysettings.xml,ivysettings,property nae(ivy.local.defalt.root
vale(*5ivy.defalt.ivy.ser.dir=/local override(false /,property nae(ivy.local.defalt.ivy.pattern vale(7organisation/7odle/ivys/ivy-7revision.xl override(false /,property nae(ivy.local.defalt.artifact.pattern vale(7organisation/7odle/7types/7artifact-7revision.7ext override(false /
,settings defaltEesolver(yresolver/ ,resolvers ,chain nae(yresolver
,filesyste nae(ylocal ,ivy pattern(*5ivy.local.defalt.root=/*5ivy.local.defalt.ivy.pattern= /
,artifact pattern(*5ivy.local.defalt.root=/*5ivy.local.defalt.artifact.pattern= /
,/filesyste ,ibiblio nae(ypblic 2copatible(tre / ,/chain ,/resolvers,/ivysettings
In ivysettings.:ml 6e have deined t6o resolvers
mylocal ilesystem based repository 6ith root at .ivy2/local as deined by variable
ivy.local.deault.root mypublic deault maven2 public repository
Ivy - Beginners Guide
-
8/11/2019 Apache Ivy Beginners Guide
21/33
Install Task 2$
Ivy pattern 7organisation/7odle/ivys/ivy-7revision.xl has placed ivy.:ml in ivys directory.
Artiact pattern 7organisation/7odle/7types/7artifact-7revision.7ext has placed 5ar7source and 5avadoc artiacts in 5ars7 sources and 5avadocs directory. ven though all three artiacts are namedas commons=lang=2.'.5ar Ivy 6ill distinguishes them by the directory name.
!hared repository
0nly dierence bet6een local and shared repository is that all users can access a shared repository and6hereas local repository is private to a user.
Deault coniguration comes 6ith a resolver named shared and it point to 0M/.ivy2/shared directory.8ut in case you dono6 ivy.shared.deault.root variable is pointed to /opt/ivy/repository/shared. ith this all users can read and6rite shared repository.
#o access this shared repository users have to override ivy.shared.deault.root variable beore callingivyBresolve 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
-
8/11/2019 Apache Ivy Beginners Guide
22/33
Install Task 22
or access the server through telnet. In enterprise set up7 developers 6or% rom des%top and repository 6ill beon 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.
dir /var/www/htl/ivyrepochown apache.apache /var/www/htl/ivyrepochod GG? /var/www/htl/ivyreposerod -a< apache H is sernaeservice httpd start H start the apache web server
As e:ample 6e are using Apache http server 6ith its deault Document root at /var/666/html. 3sers 6hoare allo6ed to install modules are added to apache group. #hese users have to use ollo6ing build.:ml toinstall the modules.
build.xml,project nae(shared repository defalt(install xlns+ivy(antlib+org.apache.ivy.ant
,target nae(install description(-- install odles to shared reporsitory
,property nae(ivy.shared.defalt.root vale(/var/www/htl/ivyrepo/ ,ivy+install organisation(coons-lang odle(coons-lang revision(2.D transitive(tre overwrite(false
fro(pblic to(shared/ ,/target,/project
Developers have to use ollo6ing ivysettings.:ml to access the repository rom their des%tops.
ivysettings.xml,ivysettings ,property nae(web.ivy.pattern vale(7organisation/7odle/7revision/7types/7artifact.7ext override(false / ,property nae(web.artifact.pattern vale(7organisation/7odle/7revision/7types/7artifact.7ext override(false / ,settings defaltEesolver(chain / ,resolvers ,chain nae(chain
,rl nae(web ,ivy pattern(http+//localhost/ivyrepo/*5web.ivy.pattern= / ,artifact pattern(http+//localhost/ivyrepo/*5web.artifact.pattern= /
,/rl ,ibiblio nae(pblic 2copatible(tre / ,/chain ,/resolvers,/ivysettings
ere 6e are using 3& resolver. Change httpB//localhost in ivy and artiact pattern to 3& o the server.
"epository Manager
eb based &epository manager li%e Archiva7 Artiactory 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
-
8/11/2019 Apache Ivy Beginners Guide
23/33
&u'lis! task 23
Chapter ! "u#lish task
ublish tas% publishes moduleo6 add ivy.:ml
ivy.xml,ivy-odle version(2.0 ,info organisation(co.xyz odle(sipleivy / ,pblications ,artifact nae(sipleivy type(jar ext(jar/ ,artifact nae(sipleivy type(javadoc ext(jar/ ,artifact nae(sipleivy type(sorce ext(jar/ ,/pblications
,dependencies ,dependency org(coons-lang nae(coons-lang rev(2.D / ,/dependencies
,/ivy-odle
#his 6ill be the descriptor or our module simpleivy. e have indicated in publications element that thispublication has three artiacts 6ith their types and e:t.
>o6 add build.:ml 6ith publish tas%
build.xml,project nae(localrepository defalt(pblish
xlns+ivy(antlib+org.apache.ivy.ant
,target nae(pblish description()blish this bild into repository ,ivy+resolve/ ,ivy+pblish pbrevision(1.0 stats(release resolver(local overwrite(tre ,artifacts pattern(7artifact-7type.7ext/ ,/ivy+pblish ,/target,/project
Ivy - Beginners Guide
-
8/11/2019 Apache Ivy Beginners Guide
24/33
&u'lis! task 24
In publish tas% 6e have given
pubrevision publication revision. 1.*
status ,tatus o revision. Ivy allo6s integration7 milestone and release as status
resolver 6e 6ant to publish the module to local repository
artiacts pattern this pattern 6ill be used by ivy to search or artiacts. 0ur artiacts has simplepattern = KartiactL=KtypeL.Ke:tL li%e simpleivy=5avadoc.5ar. #his pattern is used only to search orartiacts deined in ivy.:ml. It is important to note that 6hile placing the artiacts in repository Ivy6ill use the pattern provided in resolver deinition or layout and name the artiacts.
>o6 6e are ready to publish our simpleivy module to local repository. &un ant and it 6ill publish ourmodules to local repository as seen rom ollo6ing output.
KivyBpublishL BB publishing BB com.:y9RsimpleivyKivyBpublishL 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.5arKivyBpublishL published simpleivy to /home/m/.ivy2/local/com.:y9/simpleivy/1.*/sources/simpleivy.5arKivyBpublishL published ivy to /home/m/.ivy2/local/com.:y9/simpleivy/1.*/ivys/ivy.:ml
Ivy has used pattern given deault local resolver deinition in /org/apache/ivy/core/settings/ivysettings=local.:ml to place the iles in repository.
7organisation/7odle/7revision/7types/7artifact.7ext to place ivy.xl
7organisation/7odle/7revision/7types/7artifact.7ext 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. hen 6einvo%ed publish tas% irst it run deliver tas%. Deliver tas% generates a resolved descriptor o the module7based upon the last resolve done. #he resolved ivy ile contains updated inormation about the deliveredmodule7 such as revision and status. And this second ile is actually published to repository.
Ivy - Beginners Guide
-
8/11/2019 Apache Ivy Beginners Guide
25/33
Ivy() 25
Part II IvyDE
#his part cover
installation o Ivy and IvyD plugins
build a eclipse pro5ect 6ith Ivy
e:plore IvyD eatures
Ivy - Beginners Guide
-
8/11/2019 Apache Ivy Beginners Guide
26/33
Installation 26
Chapter 1$ Installation
,pdate !ite
,elect clipse Install >e6 ,ot6are 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 IvyD clipse plugin
select both and proceed to install. #his 6ill install ivy7 ivy ant tas%s and ivyide
Manual installation
#his method involves installation o IvyD and Ivy plugins.
IvyD lugin
#his plugin lin%s core Ivy to clipse. Do6nload the IvyD plugin romhttpB//ant.apache.org/ivy/ivyde/do6nload.cgi. -or clipse Indigo do6nload apache=ivyde=2.1.*.2*1**(1*1(*+=&A,.tar.g9 and uncompress to get t6o olders containing the artiacts to deploy
in your clipse. Copy them to eclipse installation directory as ollo6sB
plugins/org.apache.ivyde.eclipse?2.1.*.2*1**(1*1(*+=&A,.5ar to CI,?0M/pluginseatures/org.apache.ivyde.eature?2.1.*.2*1**(1*1(*+=&A,.5ar to CI,?0M/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/pluginshttpB//666.gtlib.gatech.edu/pub/apache//ant/ivyde/updatesite/eatures
-or clipse 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 CI,?0M/pluginorg.apache.ivy.eclipse.ant?2.2.*.inal?2*1**)2!2!*'2!.5ar to CI,?0M/pluginorg.apache.ivy.eature?2.2.*.inal?2*1**)2!2!*'2!.5ar to CI,?0M/eatures
Ater installation restart clipse and menu bar 6ill have &esolve button o Ivy
Ivy - Beginners Guide
-
8/11/2019 Apache Ivy Beginners Guide
27/33
Resolve 27
Chapter 11 Resolve
ets use IvyD to resolve dependencies o a 4ava ro5ect.
Create a regular 4ava ro5ect in clipse named simpleivy. Add class named ,impleIvy
in.ex.ivy.SimpleIvy.javapacage in.ex.ivy
iport org.apache.coons.lang.3tring4tils
pblic class 3iple:vy 5
pblic static void ain63tring7 args9 53tring string ( 3tring4tils.pperCase6:vy with 'clipse93yste.ot.println6string9
=
=
As e:pected clipse 6ill sho6 errors since clipse is unable to ind commons.lang in pro5ectxl version(1.0 encoding(:3%-88?@-1>,ivy-odle version(2.0 xlns+xsi(http+//www.wA.org/2001/B&3chea-instance xsi+no!aespace3cheaocation(http+//ant.apache.org/ivy/scheas/ivy.xsd
,info organisation(in.ex odle(sipleivy stats(integration ,/info
,dependencies ,dependency org(coons-lang nae(coons-lang rev(2.D / ,/dependencies,/ivy-odle
#his is the same ivy.:ml 6e had used in ant tas% earlier. Dependencies element indicates that our pro5ect isdependent on commons=lang revision 2.'. e can also use -ile=F>e6=F0ther=FIvyD=FIvy -ile i9ard toadd 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
-
8/11/2019 Apache Ivy Beginners Guide
28/33
Resolve 28
ibrary... rom the conte:t menu. IvyD 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 theConigurations to deault.
-or the moment lets not bother about other tabs = ,ettings7 &etrieve and Advanced 6hich 6e shall use in laterchapters.
Clic% on -inish. #his 6ill add libraries to clipse build path. 8ut these libraries are special in the sense thatthey are managed by IvyD. Internally IvyD 6ill use Ivy to get list dependencies mentioned in ivy.:ml andadd them to clipse 8uild ath
As soon as you clic% the -inish button Ivy goes into 5ob o resolving the dependencies you mentioned inivy.:ml. It 6ill chec% 6hether &ev 2.' is in cache else it 6ill etch rom public. rogress 8ar indicates theprogress o Ivy resolve 5ob
rrors in the pro5ect are removed once resolve is over as commons=lang is added to build path o pro5ect byIvyD.
e can add more dependency lines in ivy.:ml depending on pro5ects re;uirement. Ivy 6ill etch and IvyD6ill add them to the pro5ect build path.
et us e:plore the pro5ect build path to %no6 6hat IvyD has done. &ight clic% on the pro5ect and choose8uild ath =F Conigure 8uild ath to 4ava 8uild ath 6indo6. ,elect ibraries tab and it 6ill sho6 t6olibraries ivy.:ml and 4& ,ystem ibrary. :pand ivy.:ml entry and then commons=lang=2.'.5ar to get thelibrary details
Ivy - Beginners Guide
-
8/11/2019 Apache Ivy Beginners Guide
29/33
Resolve 2#
As 6e can see IvyD has lin%ed source and 5avadoc automatically. All dependencies mentioned in ivy.:ml6ill be added under ivy.:ml KTL
Ivy - Beginners Guide
-
8/11/2019 Apache Ivy Beginners Guide
30/33
Retrieve 3%
Chapter 12 Retrieve
&etrieve 6ill copy the dependencies to the pro5ect directory. #his is done ater Ivy completes the &esolve
step.
In IvyD 6e can enable retrieve at t6o level either at 6or%space level or at pro5ect level.
&nable "etrieve (or all proects in +orkspace
Go to indo6 =F reerences =F Ivy =F &etrieve
Ma%e changes as ollo6s and save settings
ere 6e are indicating that
IvyD has to retrieve aterresolve.
&etrieve pattern lib/KartiactL=KtypeL.Ke:tL indicates thatretrieved modules are to beplaced in lib directory
IvyD has to delete staleartiacts 6hich are no longer independencies list and lying inlib directory.
#ypes = 5ar means 6e 6ant onlyactual library 5ar iles and not5avadoc7 source 5ar etc.Multiple comma separatedtypes are allo6ed.
&eresh the pro5ect 6ith -$. ib directory is created in root older o the pro5ect and dependent 5ar commons=lang=5ar.5ar is copied to lib/deault directory.
&nable "etrieve at proect level
Ivy - Beginners Guide
-
8/11/2019 Apache Ivy Beginners Guide
31/33
Retrieve 3$
or%space level &etrieve settings 6hich 6e had enabled in previous section can be overridden at pro5ectlevel.
&ight clic% on pro5ect
-
8/11/2019 Apache Ivy Beginners Guide
32/33
*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 deined a resolver named 6eb through ivysettings.:ml to access the repository through6eb server. e can override the deault 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 theivysettings.:ml in root older o 6or%space or 6or%space level or in root older o pro5ect to override atpro5ect level.
Advanced Tab
#his tab is used to
deine accepted types
deine source types and sui:es
deines 5avadoc types and sui:es
change ordering o classpath entries
Again these things can be set at 6or%space level or at pro5ect level.
Ivy - Beginners Guide
-
8/11/2019 Apache Ivy Beginners Guide
33/33
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 IvyD eectively.
8ut it doesn