Sie sind auf Seite 1von 30

Maven 1he Comp|ete keference

Chapter 14 Andro|d App||cat|on Deve|opment w|th Maven


141 lnLroducLlon
142 Conflgurlng 8ulld LnvlronmenL for Androld uevelopmenL
143 CeLLlng SLarLed
144 CreaLlng new ro[ecLs wlLh Lhe Androld Maven ArcheLypes
143 uslng AddCns
146 MulLl Module Androld ro[ecLs
147 uslng exLernal dependencles
148 1he CusLom Llfecycle from Lhe Androld Maven lugln
149 lugln ConflguraLlon arameLers
1410 uevlce lnLeracLlon
1411 LmulaLor lnLeracLlon
1412 CLher useful Androld Maven lugln Coals
1413 lnLernal Androld Maven lugln Coals
1414 1esLlng Androld AppllcaLlon Code
1413 naLlve AppllcaLlon 8ullds
1416 1lps and 1rlcks
141 Introduct|on
Androld ls an open source moblle phone and embedded devlce operaLlng sysLem developed by
Lhe Cpen PandseL Alllance lL ls based on a Llnux kernel wlLh a vlrLual machlne envlronmenL for
managed appllcaLlon code uslng !ava byLecode for Lhe runLlme code generaLlon 1he
developmenL envlronmenL ls based on Lhe !ava language and !vM/!uk based Loollng 1he
generaLed !ava byLecode ls Lransformed lnLo ualvlk execuLable code opLlmlzed for consLralned
devlces Cnce deployed Lo Lhe devlce and execuLed Lhe code wlll run on Lhe ualvlk vlrLual
machlne !ava ls Lhe defaulL programmlng language and Lhe Al's are all !ava based
ln mosL cases developmenL of Androld appllcaLlons ls done wlLhln Lhe Lcllpse based Androld
uevelopmenL 1oolklL Au1 1he opLlonally generaLed Apache AnL based bulld can be used Lo
bulld appllcaLlons ouLslde Lhe luL 1he Androld Maven lugln was creaLed Lo allow
developmenL Leams Lo bulld deploy and release Androld appllcaLlons wlLh Apache Maven
Laklng advanLage of all Lhe powerful feaLures avallable llke dependency managemenL
reporLlng code analysls and much more
1|p
1he Androld Maven lugln ls rapldly evolvlng 1he documenLaLlon below applles Lo verslon
300alpha12 and hlgher lor up Lo daLe lnformaLlon refer Lo Lhe plugln webslLe
142 Conf|gur|ng 8u||d Lnv|ronment for Andro|d Deve|opment
8efore you aLLempL Lo bulld your Androld llbrarles and appllcaLlons wlLh Maven you wlll need
Lo lnsLall Lhe Androld Suk and poLenLlally lnsLall Lhe Androld Al [ar flles lnLo your local Maven
reposlLory or your reposlLory server
1421 Insta|||ng the Andro|d SDk
1he Androld Maven lugln requlres Lhe presence of Lhe Androld Suk ln your developmenL
envlronmenL lnsLall Lhe Suk followlng Lhe dlrecLlons on Lhe Androld ueveloper web slLe
1he Anu8Clu_PCML envlronmenL varlable should be conflgured Lo polnL Lo Lhe lnsLallaLlon
dlrecLory of Lhe Androld Suk lor example lf Lhe Suk ls lnsLalled ln /opL/androldsdkllnux Lhls
can be achleved wlLh
exporL Anu8Clu_PCML/opL/androldsdkllnux
on a unlx/bash based sysLem or
seL Anu8Clu_PCMLCopLandroldsdkllnux
on a Wlndows sysLem
ln addlLlon Lo Lhe Suk Lhe varlous plaLform verslons you need for developmenL should also be
lnsLalled followlng Lhe lnsLrucLlons ?ou can lnsLall a subseL of avallable plaLforms or slmply
lnsLall all avallable verslons
CpLlonally Lhe paLh Anu8Clu_PCML/Lools and Anu8Clu_PCML/plaLformLools can be added Lo Lhe
A1P varlable Lo allow easy command llne execuLlon of Lhe varlous Lools provlded wlLh Lhe
Suk
1422 Andro|d art|fact |nsta|| |nto Maven repos|tory
When bulldlng an Androld appllcaLlon wlLh Maven Lhe complle process needs access Lo Lhe
Androld Al for Lhe speclflc plaLform verslon Lhe pro[ecL ls conflgured agalnsL 1he Androld Suk
shlps Lhls as androld[ar flles ln Lhe dlfferenL plaLform folders ln order for Maven Lo access
Lhese llbrarles Lhey need Lo be avallable ln Lhe local Maven reposlLory
1yplcally arLlfacLs are avallable ln Maven CenLral however only Lhe plaLform verslons avallable
ln Lhe Androld Cpen Source ro[ecL are publlshed Lo Maven CenLral newer verslons of Lhe
plaLform as well as Lhe compaLlblllLy package and proprleLary exLenslons llke Lhe Coogle Maps
supporL are noL avallable Lhere and need Lo be publlshed Lo your Maven reposlLory lf you wanL
Lo use Lhem ln your Androld pro[ecL
1he arLlfacLs publlshed Lo Maven cenLral are avallable as dependencles under Lhe groupld
comgoogleandrold wlLh Lhe arLlfacLld androld and androldLesL
1he Maven Androld Suk ueployer has been creaLed Lo publlsh arLlfacLs from Lhe Androld Suk
lnLo your local reposlLory or reposlLory server when uslng componenLs LhaL are noL avallable ln
CenLral
uownload Lhe Lool by cllcklng on Lhe uownload Source buLLon and exLracL Lhe downloaded zlp or
Lar archlve ln a folder of your cholce A folder wlLh a namlng paLLern of mosabuamaven
androldsdkdeployerxxx wlLh xxx belng a revlslon number llke df824df wlll be creaLed
Insta||at|on to |oca| repos|tory
ln order Lo lnsLall Lhe androld [ar flles from Lhe dlfferenL plaLform revlslons lnLo your local
reposlLory you run Lhe command ln Lhe deployer folder
cd mosabuamavenandroldsdkdeployerdf824df
mvn clean lnsLall
8y defaulL Lhls wlll lnsLall all androld[ar maps[ar usb[ar flles and Lhe compaLlbllLy packages
lnLo your local Maven reposlLory ?ou should flnd all newly lnsLalled flles ln Lhe androld
comgoogleandroldmaps comandroldfuLure and androldsupporL group ldenLlflers under
/m2/teposltoty
Insta||at|on to remote repos|tory
1he above deploymenL works flne for one machlne buL lf you need Lo supply a whole Leam of
developers and a clusLer of bulld machlnes wlLh Lhe arLlfacLs you wlll wanL Lo deploy Lhe
arLlfacLs once Lo a remoLe reposlLory server LhaL ls avallable Lo all users lf you are noL currenLly
uslng a reposlLory manager you should download nexus and conflgure a user wlLh permlsslon
Lo deploy arLlfacLs Lo a reposlLory 1o geL sLarLed wlLh nexus read Lhe nexus lnsLallaLlon
chapLer ln Lhe free onllne nexus book
As a flrsL sLep you wlll need Lo edlL Lhe repourl properLy ln Lhe pomxml ln Lhe Lop folder of Lhe
Maven Androld Suk ueployer Lool Lo polnL Lo Lhe reposlLory you wanL Lo publlsh Lo
AlLernaLlvely you can provlde Lhls properLy ln Lhe seLLlngs flle or wlLh urepourlLheurl on Lhe
command llne
1hen you need Lo add a server wlLh Lhe correcL access credenLlals for Lhe server Lo your Maven
SeLLlngs flle
Sn|ppet for sett|ngsxm| for the repos|tory server access credent|a|s
seLLlngs
servers
server
ldandroldrepo/ld
usernameyour username/username
passwordyour password/password
/server
/servers
/seLLlngs
Cnce LhaL conflguraLlon ls compleLed you can deploy Lhe arLlfacLs wlLh Lhe command mvn
deploy As a resulL you should flnd Lhe arLlfacL ln Lhe reposlLory of your remoLe server
Insta||at|on of a subset of a|| p|atforms
8y defaulL Lhe Maven Androld Suk ueployer Lool wlll aLLempL Lo lnsLall or deploy all verslons of
Lhe plaLforms arLlfacLs lnLo a reposlLory lf you declde Lo only lnsLall a subseL of Lhe componenLs
Lhe Lool can be used wlLh proflle opLlons Lo only lnsLall or deploy some arLlfacLs 1hls can be
done by speclfylng Lhe plaLform Al verslons as a proflle name
mvn lnsLall 32
lurLher deLalls are avallable ln Lhe Maven Androld Suk ueployer documenLaLlon
143 Gett|ng Started
1he PellollashllghL example appllcaLlon serves as a sLarLlng polnL Lo lnLroduce you Lo Lhe usage
of Lhe Androld Maven lugln 1he code for Lhe helloflashllghL example appllcaLlon as well as
varlous more complex examples are avallable as parL of Lhe plugln samples pro[ecL
1o enable a Maven based bulld of an Androld pro[ecL a pomxml has Lo be added ln Lhe rooL
folder of Lhe pro[ecL
1he ne||oI|ash||ght pomxm| f||e
?xml verslon10 encodlngu1l8?
pro[ecL xmlnshLLp//mavenapacheorg/CM/400
xmlnsxslhLLp//wwww3org/2001/xMLSchemalnsLance
xslschemaLocaLlonhLLp//mavenapacheorg/CM/400 hLLp//mavenapacheorg/mavenv4_0_0xsd
modelverslon400/modelverslon
groupldcomslmpllglllLyandrold/groupld
arLlfacLldhelloflashllghL/arLlfacLld
verslon100SnASPC1/verslon
packaglngapk/packaglng
namePellollashllghL/name

dependencles
dependency
groupldcomgoogleandrold/groupld
arLlfacLldandrold/arLlfacLld
verslon16_r2/verslon
scopeprovlded/scope
/dependency
/dependencles
bulld
flnalname$pro[ecLarLlfacLld/flnalname
sourceulrecLorysrc/sourceulrecLory
pluglnManagemenL
pluglns
plugln
groupldcom[aywaymavenpluglnsandroldgeneraLlon2/groupld
arLlfacLldandroldmavenplugln/arLlfacLld
verslon300SnASPC1/verslon
exLenslonsLrue/exLenslons
/plugln
/pluglns
/pluglnManagemenL
pluglns
plugln
groupldcom[aywaymavenpluglnsandroldgeneraLlon2/groupld
arLlfacLldandroldmavenplugln/arLlfacLld
conflguraLlon
run
debugLrue/debug
/run
sdk
plaLform4/plaLform
/sdk
emulaLor
avd16/avd
/emulaLor
undeploy8eforeueployLrue/undeploy8eforeueploy
/conflguraLlon
/plugln
/pluglns
/bulld
/pro[ecL
1he hlghllghLs of Lhls pomxml are
O Lhe packaglng Lype of apk
O Lhe dependency Lo Lhe Androld plaLform [ar
O and Lhe bulld conflguraLlon wlLh Lhe Androld Maven lugln
1he Androld ackage packaglng Lype apk ls whaL acLlvaLes Lhe Androldspeclflc llfecycle
modlflcaLlons of Lhe Androld Maven lugln lL Lakes care of all Lhe speclflc calls Lo Lhe Androld
Suk Lools LhaL process resources converL !ava byLecode and so on 1he Androld Maven lugln
needs Lo be conflgured wlLh exLenslons seL Lo Lrue for Lhls Lo work as vlslble ln Lhe
pluglnManagemenL secLlon
1he declared dependency Lo Lhe androld plaLform [ar ls avallable ln Maven CenLral wlLh varlous
plaLform verslons AlLernaLlvely you could use an Androld [ar from Lhe Maven Androld Suk
ueployer wlLh Lhe modlfled groupld and arLlfacLld 1he documenLaLlon of Lhe deployer shows
all valld dependencles
1he scope of provlded ls lmporLanL lL slgnals Lo Maven LhaL Lhe conLenLs of Lhe [ar wlll noL need
Lo be packaged lnLo Lhe appllcaLlon package because Lhey are avallable aL runLlme on Lhe
devlce as parL of Lhe envlronmenL
ln addlLlon Lhe androld [ar arLlfacLs only conLaln excepLlon Lhrowlng sLubs for all meLhods ln
order Lo deflne Lhe Al for Lhe compller 1hey can noL be execuLed on Lhe developmenL
machlne buL rely on an emulaLor or devlce runLlme envlronmenL
1he conflguraLlon of Lhe Androld Maven lugln ls done ln Lhe bulld secLlon lnlLlally only Lhe sdk
plaLform parameLer ls requlred Lo be speclfled ?ou can use elLher a plaLform verslon number
or a Al level number as documenLed on Lhe Androld developer documenLaLlon
1|p
1he verslon of Lhe Androld Maven lugln ln Lhe pom flle ls a developmenL verslon 8eplace lL
wlLh Lhe laLesL released verslon when runnlng Lhe example yourself or download Lhe sLable
branch of Lhe samples
1o bulld Lhe appllcaLlon and run lL on an already sLarLed emulaLor or aLLached devlce you could
use
mvn lnsLall androlddeploy androldrun
144 Creat|ng New ro[ects w|th the Andro|d Maven
Archetypes
When sLarLlng a fresh pro[ecL lL ls easy Lo use Lhe Maven ArcheLype lugln Lo creaLe a skeleLon
Lo sLarL worklng wlLh lorLunaLely mulLlple archeLypes for Androld pro[ecLs are avallable
?ou can creaLe a new androldqulcksLarL pro[ecL whlch ls slmllar Lo Lhe helloflashllghL example
on Lhe command llne wlLh
mvn archeLypegeneraLe
uarcheLypeArLlfacLldandroldqulcksLarL
uarcheLypeCrouplddeakqulneLandroldarcheLypes
uarcheLypeverslon106
ugroupldyourcompany
uarLlfacLldmyandroldappllcaLlon
CLher archeLypes avallable are an Androld pro[ecL lncludlng LesL execuLlon wlLh Lhe
archeLypeArLlfacLld androldwlLhLesLarcheLype and a pro[ecL wlLh release process conflguraLlon
androldreleasearcheLype
Note
Many developmemL envlronmenLs have a vlsual lnLegraLlon of creaLlng new pro[ecLs wlLh a
Maven archeLype so you can use LhaL lnsLead of Lhe command llne
14S Us|ng AddCns
lor many appllcaLlons Lhe normal Androld Suk arLlfacL (androld[ar) wlll be sufflclenL however
some appllcaLlons requlre addons Cne of Lhe more commonly used addons ls Lhe Coogle
Maps addon whlch provldes access Lo Lhe Coogle Maps Al 1he Maps addon ls deployed Lo
your Maven reposlLory by Lhe Maven Androld Suk ueployer Lool 1o use an add on you [usL
have Lo add Lhe respecLlve dependency Lo your pom flle
1he dependency to the Goog|e Maps AI
dependency
groupldcomgoogleandroldmaps/groupld
arLlfacLldmaps/arLlfacLld
verslon7_r1/verslon
scopeprovlded/scope
/dependency
AnoLher common addon ls Lhe compaLlblllLy llbrary lL needs Lo be lncluded ln Lhe produced
apk and Lhere does noL have provlded scope
1he dependency to the compat|b|||ty ||brary for AI v4 and up
dependency
groupldandroldsupporL/groupld
arLlfacLldcompaLlblllLyv4/arLlfacLld
verslonr3/verslon
/dependency
146 Mu|t| Modu|e Andro|d ro[ects
1he Androld Maven lugln can be used ln a mulLlmodule pro[ecL seLup An example seLup
would be 3 dlfferenL modules llnked vla a parenL pom
!ava Llbrary Code
1hls flrsL module could conLaln any buslness loglc lmplemenLed ln !ava or any oLher
!vM based language acLually ln a [ar package
Androld AppllcaLlon Code
1hls second module would depend on Lhe flrsL module and conslsL of all Lhe lnLerface
code for Lhe Androld plaLform lL would need Lo use apk packaglng and Lhe Maven
Androld lugln
lnsLrumenLaLlon 1esL
1hls Lhlrd module would depend on Lhe second module and lmplemenL Lhe lnLegraLlon
LesL of Lhe appllcaLlon
1ogeLher wlLh Lhe use of oLher modules Lo separaLe lLems lL ls posslble Lo seL up a mulLl module
bulld for an Androld appllcaLlon as well as a server slde web appllcaLlon sharlng eg Lhe code
for Lhe core ob[ecLs and buslness loglc
A comprehenslve example seLup llke Lhls called morseflash ls parL of Lhe samples pro[ecL for Lhe
plugln
147 Us|ng externa| dependenc|es
When uslng Lhe Androld Maven lugln Lhere are Lhree Lypes of dependencles LhaL are LreaLed
dlfferenLly
8egular dependencles Lo oLher !ava llbrarles
1he !ava byLe code flles (class) of llbrary dependencles as denoLed ln Lhe normal Maven
way are Lransformed Lo dalvlk execuLable formaL llke any source code of Lhe currenL
pro[ecL and lncluded ln Lhe Androld package All oLher flles are lncluded as conLalned ln
Lhe source llbrary An example would look llke Lhls
dependency
groupldcomslmpllglllLy/groupld
arLlfacLldmodel/arLlfacLld
verslon01/verslon
/dependency
uependencles Lo oLher Androld pro[ecLs
CLher Maven Androld pro[ecLs wlLh packaglng Lype apk declared as dependencles are
deployed Lo Lhe emulaLor prlor Lo runnlng Lhe lnsLrumenLaLlon LesLs ln Lhe lnLegraLlon
LesL phase
dependency
groupldcomslmpllglllLyandrold/groupld
arLlfacLldlnLenLs/arLlfacLld
verslon01/verslon
Lypeapk/Lype
/dependency
uependencles Lo oLher Androld pro[ecLs sources
CLher Androld Maven pro[ecLs wlLh packaglng Lype apk declared as source
dependencles are pulled lnLo Lhe currenL Androld appllcaLlon wlLh asseLs and resources
and used Lo bulld an appllcaLlon comblnlng all arLlfacLs lncludlng resources
dependency
groupldcomslmpllglllLyandrold/groupld
arLlfacLldLools/arLlfacLld
verslon01/verslon
Lypeapkllb/Lype
/dependency
1|p
A common use case for uslng Androld llbrarles ls Lo separaLe ouL all appllcaLlon code LhaL ls
lndependenL of Lhe appllcaLlon sLore ln whlch Lhe apk wlll be made avallable 1hen you can
have one apk per sLore LhaL depends on Lhe llbrary and add any speclflc code for eg markeL
access or release bulld requlremenLs
148 1he Custom L|fecyc|e from the Andro|d Maven |ug|n
1he Androld Maven lugln cusLomlzes Lhe llfecycle based on Lhe packaglng lf your pro[ecL has a
packaglng of Lype apk Lhe cusLomlzed llfecycle wlll be used
1he cusLomlzed llfecycle has Lhe followlng addlLlonal execuLlons ln Lhe defaulL llfecycle
generaLesources hase
use Lhe Androld AsseL ackaglng 1ool (aapL) of Lhe plaLform verslon speclfled ln Lhe pom
Lo package Lhe Androld speclflc resources llke AndroldManlfesLxml asseLs and resources
AddlLlonal parameLers can be passed Lo aapL wlLh Lhe parameLer aapLLxLraArgs
processclasses hase
8un Lhe dx Lool of Lhe plaLform verslon speclfled ln Lhe pom Lo converL all classes
(llbrarles resources and pro[ecL code) lnLo davllk execuLable formaL
package hase
8un Lhe Androld ackage Lool (apk) of Lhe Androld Suk Lo creaLe and slgn Lhe Androld
package flle (apk) for lnsLallaLlon on Lhe emulaLor or devlce
prelnLegraLlonLesL hase
ueploy Lhe currenLly bullL Androld appllcaLlon package (apk) as well as any oLher
dependencles wlLh packaglng Lype apk Lo Lhe emulaLor/devlce
lnLegraLlonLesL hase
8un Lhe lnsLrumenLaLlon LesL classes agalnsL Lhe deployed appllcaLlon
149 |ug|n Conf|gurat|on arameters
1he Androld Maven lugln supporLs a large number of conflguraLlon parameLers 1hey can
Lyplcally be passed lnLo Lhe execuLlon as plugln conflguraLlon as properLles deflned ln Lhe pom
or seLLlngs flle or as command llne parameLers
An examp|e of a p|ug|n conf|gurat|on
conflguraLlon
sdk
plaLform21/plaLform
/sdk
emulaLor
avd21/avd
opLlonsnoskln/opLlons
/emulaLor
/conflguraLlon
Conf|gurat|on as propert|es |n pomxm|
properLles
androldemulaLoravd21/androldemulaLoravd
properLles
Conf|gurat|on on command ||ne |nvocat|on
mvn androldemulaLorsLarL uandroldemulaLoravd21
A number of oLher parameLers have defaulLs LhaL polnL Lo Lhe defaulL locaLlon as used by Lhe
sLandard Androld/Lcllpse pro[ecL layouL buL can be cusLomlzed lf deslred
O androldManlfesLllle
O asseLsulrecLory
O resourceulrecLory
O sourceulrecLorles
Some of Lhe oLher useful parameLers are
devlce
Speclfy usb emulaLor or a speclflc serlal number 8ead SecLlon 1410 uevlce lnLeracLlon"
for more lnformaLlon
undeploy8eforeueploy
1hls parameLer wlll cause Lhe appllcaLlon as well as Lhe LesL appllcaLlon Lo be
undeployed from Lhe devlce before each deploymenL
1410 Dev|ce Interact|on
1he Androld Maven lugln has powerful feaLures for lnLeracLlng wlLh aLLached devlces and
emulaLors lmplemenLed ln a number of goals 1hey use Lhe androlddevlce parameLer Lo
deLermlne a speclflc devlce as speclfled by Lhe serlal number all connecLed emulaLors or all
connecLed devlces should be affecLed A value of emulaLor wlll Lrlgger execuLlon on all emulaLors
connecLed vla adb and a value of usb wlll affecL all devlces
1he followlng goals supporL Lhe devlce parameLer and sequenLlal execuLlon agalnsL all devlces
androlddeploy
1he deploy goal deploys Lhe bullL apk flle or anoLher speclfled apk Lo Lhe connecLed
devlce(s) 1hls goal ls auLomaLlcally performed when runnlng Lhrough Lhe lnLegraLlonLesL
llfecycle phase on a pro[ecL wlLh lnsLrumenLaLlon LesLs (eg mvn lnsLall or mvn lnLegraLlon
LesL)
androldundeploy
1he undeploy goal removes Lhe apk of Lhe currenL pro[ecL or anoLher speclfled apk from
Lhe connecLed devlces and emulaLors
androldredeploy
1he redeploy goal execuLes undeploy and deploy consecuLlvely on all speclfled devlces
and emulaLors
androldlnsLrumenL
1he lnsLrumenL goal runs Lhe lnsLrumenLaLlon LesLs afLer auLomaLlcally deploylng Lhe LesL
appllcaLlon and Lhe LesLs lL honors Lhe sLandard Maven sklp LesL properLles as well as
androldLesLsklp lL supporLs a number of furLher parameLers LhaL are explalned ln more
deLall ln SecLlon 1414 1esLlng Androld AppllcaLlon Code"
androldpull
1he pull goal can be used Lo copy a flle or dlrecLory from Lhe devlce Source and
desLlnaLlon flle have Lo be speclfled wlLh Lhe androldpullsource and androldpulldesLlnaLlon
conflguraLlon parameLers
androldpush
1he push goal can be used Lo copy a flle or dlrecLory Lo Lhe devlce ConflguraLlon ls done
wlLh Lhe androldpushsource and androldpushdesLlnaLlon parameLers
androldrun
1he run goal wlll sLarL Lhe appllcaLlon on Lhe devlce lf Lhe rundebug paramLer ls seL Lo
Lrue sLarLlng wlll walL for a debugger Lo connecL
1411 Lmu|ator Interact|on
1he emulaLorsLarL goal can sLarL an exlsLlng Androld devlce emulaLor 1he sLarL up can be
conflgured wlLh Lhe parameLers emulaLoravd speclfylng Lhe name of Lhe vlrLual devlce
emulaLorwalL speclfylng a walL perlod and emulaLoropLlons speclfylng furLher command llne
opLlons passed Lo Lhe emulaLor command
1he emulaLorsLop and emulaLorsLopall goals sLop Lhe speclfled or all aLLached Androld
emulaLor(s)
1412 Cther Usefu| Andro|d Maven |ug|n Goa|s
A number of plugln goals are useful for manual execuLlon or cusLom blndlng Lo a llfecycle phase
eg ln a release proflle
14121 Man|festupdate
1he manlfesLupdaLe goal can be used Lo do ln place updaLes Lo Lhe AndroldManlfesLxml flle lL
can updaLe a number of parameLers llke verslonname verslonCode and oLhers and supporLs
Lhe parameLers manlfesLverslonname manlfesLverslonCode manlfesLverslonCodeAuLolncremenL
manlfesLverslonCodeupdaLelromverslon manlfesLshareduserld and manlfesLdebuggable
14122 2|pa||gn
1he zlpallgn goal can execuLe Lhe zlpallgn command as requlred for creaLlon an apk for upload Lo
Lhe Androld MarkeL lL supporLs Lhe parameLers zlpallgnsklp zlpallgnverbose zlpallgnlnpuLApk and
zlpallgnouLpuLApk
14123 ne|p
1he help goal provldes overall as well as plugln goal speclflc help on Lhe command llne
1413 Interna| Andro|d Maven |ug|n Goa|s
1he Androld Maven lugln supporLs a number of goals LhaL are parL of Lhe defaulL llfecycle and
are lnvoked auLomaLlcally ln mosL cases you wlll noL have Lo lnvoke Lhese goals dlrecLly buL lL
can be useful Lo know abouL Lhem and Lhelr conflguraLlon opLlons
androldapk
1he apk goal creaLes Lhe androld package (apk) flle 8y defaulL Lhe plugln slgns Lhe flle
wlLh Lhe debug keysLore 1he conflguraLlon parameLer slgndebugfalsedebugslgn can
be used Lo dlsable Lhe slgnlng process
androlddeploydependencles
1he deploydependencles goal deploys all dlrecLly declared dependencles of Lypeapk/Lype
ln Lhls pro[ecL 1hls goal ls usually used ln a pro[ecL wlLh lnsLrumenLaLlon LesLs Lo deploy
Lhe apk Lo LesL onLo Lhe devlce before runnlng Lhe deploylng and runnlng Lhe
lnsLrumenLaLlon LesLs apk 1he goal ls auLomaLlcally performed when runnlng Lhrough
Lhe lnLegraLlonLesL llfe cycle phase on a pro[ecL wlLh lnsLrumenLaLlon LesLs (eg mvn
lnsLall or mvn lnLegraLlonLesL)
androlddex
1he dex goal converLs complled !ava classes Lo Lhe Androld uallvk LxecuLable (dex)
formaL 1he dex execuLlon can be conflgured wlLh Lhe parameLers dex[vmArgumenLs
dexcoreLlbrary dexnoLocals and dexopLlmlze
androldgeneraLesources
1he generaLesources goal generaLes 8[ava based on Lhe resources speclfled by Lhe
resources conflguraLlon parameLer lL generaLes !ava flles based on aldl flles lf Lhe
conflguraLlon parameLer deleLeConfllcLlngllles ls Lrue (whlch lL ls by defaulL) Lhls goal has
also deleLes any 8[ava flles found ln Lhe source dlrecLory deleLes any [ava flles wlLh Lhe
same name as an aldl flle found ln Lhe source dlrecLory and deleLes any 1humbsdb flles
found ln Lhe resource dlrecLory
androldlnLernallnLegraLlonLesL
1he lnLernallnLegraLlonLesL goal ls called auLomaLlcally when Lhe llfecycle reaches Lhe
lnLegraLlonLesL phase lL deLermlnes wheLher Lo call Lhe goal lnsLrumenL ln Lhls phase
based on Lhe exlsLence of lnsLrumenLaLlon LesL classes ln Lhe currenL pro[ecL 1he goal ls
lnLernal Lo Lhe plugln llfecycle and should noL be used as separaLe lnvocaLlon on Lhe
command llne
androldlnLernalprelnLegraLlonLesL
1he lnLernalprelnLegraLlonLesL goal ls called auLomaLlcally when Lhe llfecycle reaches pre
lnLegraLlonLesL phase lL deLermlnes wheLher Lo call Lhe goals androlddeploydependencles
and androlddeploy ln Lhls phase and lf necessary lnvokes Lhem 1he goal ls lnLernal Lo Lhe
plugln llfecycle and should noL be used as separaLe lnvocaLlon on Lhe command llne
1414 1est|ng Andro|d App||cat|on Code
1esLlng Androld AppllcaLlon code can be done ln a unlL LesL fashlon wlLh rlch [unlL supporL as
parL of Lhe Androld Suk as well as lnLegraLlon Lype LesLlng called lnsLrumenLaLlon LesLlng
14141 Un|t tests
1he Androld Maven lugln lncludes Lhe execuLlon of Lhe Sureflre plugln and as such unlL LesLs
can be lncluded ln Lhe pro[ecL llke ln any oLher pro[ecL 1he defaulL paLh for LesL classes ln Lhe
Lcllpse and Lherefore Androld uevelopmenL 1oolklL ls LesL and Lherefore Maven has Lo be
conflgured Lo access code from Lhere wlLh Lhe conflguraLlon
Add|ng the test fo|der to the bu||d conf|gurat|on
bulld
LesLSourceulrecLoryLesL/LesLSourceulrecLory

AlLernaLlvely Lhe Maven convenLlons can be lmplemenLed by movlng Lhe source code for Lhe
appllcaLlon and Lhe LesL source code lnLo src/maln/[ava and src/LesL/[ava and reconflgurlng Lhe
Lcllpse pro[ecL flles
14142 Instrumentat|on tests
lnsLrumenLaLlon LesLs are lnLegraLlon LesLs bundled lnLo an appllcaLlon LhaL run on Lhe
emulaLor or devlce and lnLeracL wlLh anoLher deployed appllcaLlon Lo LesL Lhe behavlour 1he
common seLup Lo run lnsLrumenLaLlon LesLs would be Lwo parallel pro[ecLs one for Lhe
appllcaLlon and one for Lhe lnsLrumenLaLlon LesLs 1hese modules are Lled LogeLher as modules
of a parenL pom
1he Androld Maven lugln samples conLalns Lhe morseflash as well as Lheapldemos13
examples for a pro[ecL seL up ln Lhls manner 1he seLup of Lhe lnsLrumenLaLlon LesL appllcaLlon
wlLh Lhe Androld Maven lugln ls Lhe same as for a normal appllcaLlon wlLh Lhe added
dependency Lo Lhe appllcaLlon LhaL needs Lo be LesLed lL ls lmporLanL Lo add Lhe Lype of apk Lo
Lhe dependency Lo allow Lhe Androld Maven lugln Lo flnd Lhe Androld package of Lhe
appllcaLlon
dependency
groupldcomslmpllglllLyandrold/groupld
arLlfacLldlnLenLs/arLlfacLld
verslon01/verslon
Lypeapk/Lype
/dependency
lnsLrumenLaLlon LesL execuLlon supporLs a large number of conflguraLlon parameLers LhaL are
dlsplayed ln Lhe plugln conflguraLlon layouL ln Avallable parameLers for lnsLrumenLaLlon LesLlng
Ava||ab|e parameters for |nstrumentat|on test|ng
LesL
sklpLrue|false|auLo/sklp
lnsLrumenLaLlonackagepackagename/lnsLrumenLaLlonackage
lnsLrumenLaLlon8unnerclassname/lnsLrumenLaLlon8unner
debugLrue|false/debug
coverageLrue|false/coverage
logonlyLrue|false/logonly avd
LesLslzesmall|medlum|large/LesLslze
creaLereporLLrue|false/creaLereporL
classes
classyourpackagename?our1esLClass/class
/classes
packages
packageyourpackagename/package
/packages
/LesL
unless creaLereporL ls seL Lo false Lhe lnsLrumenLaLlon LesL run wlll produce [unlL xml compaLlble
LesL ouLpuL ln Lhe bulld ouLpuL folder for LesL resulLs LargeL/sureflrereporLs for each devlce or
emulaLor Lhe LesLs run on
141S Nat|ve App||cat|on 8u||ds
1he Androld Maven lugln supporLs bulldlng appllcaLlon LhaL lnclude naLlve code as well ueflne
Lhe envlronmenL varlable Anu8Clu_nuk_PCML Lo polnL Lo Lhe requlred Androld nuk
lnsLallaLlon and have a look aL Lhe naLlve pro[ecLs ln Lhe samples of Lhe plugln for more deLalls
1416 1|ps and 1r|cks
14161 Cther Maven |ug|ns
AparL from Lhe feaLures of Lhe Androld Maven lugln you have access Lo all Lhe oLher Maven
pluglns Lo auLomaLe Lhlngs llke llcense header flle checks resource fllLerlng and many more
14162 erform|ng a ke|ease 8u||d
A release bulld for an Androld appllcaLlon needs Lo creaLe an apk flle LhaL has been slgned and
zlpallgned ln addlLlon lL ls advlseable Lo run shrlnklng and obfuscaLlon All Lhese sLeps can be
done wlLh Lhe Maven !arslgner lugln Lhe roguard Maven lugln and Lhe zlpallgn goal of Lhe
Androld Maven lugln A sample conflguraLlon of a release bulld ls avallable ln Lhe morseflash
example appllcaLlon of Lhe plugln samples
14163 Conf|gur|ng command ||ne usage
ln order Lo use Lhe Androld Maven lugln goals on Lhe command llne wlLh Lhe shorL plugln
name androld ouLslde a dlrecLory LhaL conLalns a reference Lo Lhe plugln you have Lo add Lhe
followlng pluglnCroups snlppeL Lo your seLLlngsxml flle
Sn|ppet for sett|ngsxm| to enab|e short p|ug|n name usage
pluglnCroups
pluglnCroup
com[aywaymavenpluglnsandroldgeneraLlon2
/pluglnCroup
/pluglnCroups
Chapter 1S Append|x Sett|ngs Deta||s
1S1 u|ck Cverv|ew
1he seLLlngs elemenL ln Lhe settloqsxml flle conLalns elemenLs used Lo deflne values whlch
conflgure Maven execuLlon SeLLlngs ln Lhls flle are seLLlngs whlch apply Lo many pro[ecLs and
whlch should noL be bundled Lo any speclflc pro[ecL or dlsLrlbuLed Lo an audlence 1hese
lnclude values such as Lhe local reposlLory locaLlon alLernaLe remoLe reposlLory servers and
auLhenLlcaLlon lnformaLlon 1here are Lwo locaLlons where a settloqsxml flle may llve
O Maven lnsLallaLlon ulrecLory ,2_nO,/coof/settloqsxml
O userspeclflc SeLLlngs llle /m2/settloqsxml
Pere ls an overvlew of Lhe Lop elemenLs under seLLlngs
Cverv|ew of top|eve| e|ements |n sett|ngsxm|
seLLlngs xmlnshLLp//mavenapacheorg/SL11lnCS/100
xmlnsxslhLLp//wwww3org/2001/xMLSchemalnsLance
xslschemaLocaLlonhLLp//mavenapacheorg/SL11lnCS/100
hLLp//mavenapacheorg/xsd/seLLlngs100xsd

local8eposlLory/
lnLeracLlveMode/
uselugln8eglsLry/
offllne/
pluglnCroups/
servers/
mlrrors/
proxles/
proflles/
acLlveroflles/
/seLLlngs
1S2 Sett|ngs Deta||s
1S21 S|mp|e Va|ues
Palf of Lhe Loplevel seLLlngs elemenLs are slmple values represenLlng a range of values whlch
conflgure Lhe core behavlor of Maven
S|mp|e top|eve| e|ements |n sett|ngsxm|
seLLlngs xmlnshLLp//mavenapacheorg/SL11lnCS/100
xmlnsxslhLLp//wwww3org/2001/xMLSchemalnsLance
xslschemaLocaLlonhLLp//mavenapacheorg/SL11lnCS/100
hLLp//mavenapacheorg/xsd/seLLlngs100xsd
local8eposlLory$userdlr/m2/reposlLory/local8eposlLory
lnLeracLlveModeLrue/lnLeracLlveMode
uselugln8eglsLryfalse/uselugln8eglsLry
offllnefalse/offllne
pluglnCroups
pluglnCrouporgcodehausmo[o/pluglnCroup
/pluglnCroups

/seLLlngs
1he slmple Loplevel elemenLs are
local8eposlLory
1hls value ls Lhe paLh of Lhls bulld sysLem's local reposlLory 1he defaulL value ls
setJlt/m2/teposltoty
lnLeracLlveMode
Lrue lf Maven should aLLempL Lo lnLeracL wlLh Lhe user for lnpuL false lf noL uefaulLs Lo
Lrue
uselugln8eglsLry
Lrue lf Maven should use Lhe setJlt/m2/plqloteqlsttyxml flle Lo manage plugln
verslons defaulLs Lo false
offllne
Lrue lf Lhls bulld sysLem should operaLe ln offllne mode defaulLs Lo false 1hls elemenL ls
useful for bulld servers whlch cannoL connecL Lo a remoLe reposlLory elLher because of
neLwork seLup or securlLy reasons
pluglnCroups
1hls elemenL conLalns a llsL of pluglnCroup elemenLs each conLalns a groupld 1he llsL ls
searched when a plugln ls used and Lhe groupld ls noL provlded ln Lhe command llne 1hls
llsL conLalns orgapachemavenpluglns by defaulL
1S22 Servers
1he dlsLrlbuLlonManagemenL elemenL of Lhe CM deflnes Lhe reposlLorles for deploymenL
Powever cerLaln seLLlngs such as securlLy credenLlals should noL be dlsLrlbuLed along wlLh Lhe
pomxml 1hls Lype of lnformaLlon should exlsL on Lhe bulld server ln Lhe settloqsxml
Server conf|gurat|on |n sett|ngsxm|
seLLlngs xmlnshLLp//mavenapacheorg/SL11lnCS/100
xmlnsxslhLLp//wwww3org/2001/xMLSchemalnsLance
xslschemaLocaLlonhLLp//mavenapacheorg/SL11lnCS/100
hLLp//mavenapacheorg/xsd/seLLlngs100xsd

servers
server
ldserver001/ld
usernamemy_logln/username
passwordmy_password/password
prlvaLekey$userhome/ssh/ld_dsa/prlvaLekey
passphrasesome_passphrase/passphrase
flleermlsslons664/flleermlsslons
dlrecLoryermlsslons773/dlrecLoryermlsslons
conflguraLlon/conflguraLlon
/server
/servers

/seLLlngs
1he elemenLs under server are
ld
1hls ls Lhe ld of Lhe server (noL of Lhe user Lo logln as) LhaL maLches Lhe
dlsLrlbuLlonManagemenL reposlLory elemenL's ld
username password
1hese elemenLs appear as a palr denoLlng Lhe logln and password requlred Lo
auLhenLlcaLe Lo Lhls server
prlvaLekey passphrase
Llke Lhe prevlous Lwo elemenLs Lhls palr speclfles a paLh Lo a prlvaLe key (defaulL ls
setbome/ssb/lJ_Jso) and a passphrase lf requlred 1he passphrase and password
elemenLs may be exLernallzed ln Lhe fuLure buL for now Lhey musL be seL plalnLexL ln
Lhe settloqsxml flle
flleermlsslons dlrecLoryermlsslons
When a reposlLory flle or dlrecLory ls creaLed on deploymenL Lhese are Lhe permlsslons
Lo use 1he legal values of each ls a Lhree dlglL number correspondlng Lo *nlx flle
permlsslons le 664 or 773
1S23 M|rrors
M|rror conf|gurat|on |n sett|ngsxm|
seLLlngs xmlnshLLp//mavenapacheorg/SL11lnCS/100
xmlnsxslhLLp//wwww3org/2001/xMLSchemalnsLance
xslschemaLocaLlonhLLp//mavenapacheorg/SL11lnCS/100
hLLp//mavenapacheorg/xsd/seLLlngs100xsd

mlrrors
mlrror
ldplaneLmlrrorcom/ld
namelaneLMlrror AusLralla/name
urlhLLp//downloadsplaneLmlrrorcom/pub/maven2/url
mlrrorCfcenLral/mlrrorCf
/mlrror
/mlrrors

/seLLlngs
ld name
1he unlque ldenLlfler of Lhls mlrror 1he ld ls used Lo dlfferenLlaLe beLween mlrror
elemenLs
url
1he base u8L of Lhls mlrror 1he bulld sysLem wlll use prepend Lhls u8L Lo connecL Lo a
reposlLory raLher Lhan Lhe defaulL server u8L
mlrrorCf
1he ld of Lhe server LhaL Lhls ls a mlrror of lor example Lo polnL Lo a mlrror of Lhe
Maven cenLral server (hLLp//repo1mavenorg/maven2) seL Lhls elemenL Lo cenLral
1hls musL noL maLch Lhe mlrror ld
1S24 rox|es
roxy conf|gurat|on |n sett|ngsxm|
seLLlngs xmlnshLLp//mavenapacheorg/SL11lnCS/100
xmlnsxslhLLp//wwww3org/2001/xMLSchemalnsLance
xslschemaLocaLlonhLLp//mavenapacheorg/SL11lnCS/100
hLLp//mavenapacheorg/xsd/seLLlngs100xsd

proxles
proxy
ldmyproxy/ld
acLlveLrue/acLlve
proLocolhLLp/proLocol
hosLproxysomewherecom/hosL
porL8080/porL
usernameproxyuser/username
passwordsomepassword/password
nonroxyPosLs*googlecom|lblblloorg/nonroxyPosLs
/proxy
/proxles

/seLLlngs
ld
1he unlque ldenLlfler for Lhls proxy 1hls ls used Lo dlfferenLlaLe beLween proxy
elemenLs
acLlve
Lrue lf Lhls proxy ls acLlve 1hls ls useful for declarlng a seL of proxles buL only one may
be acLlve aL a Llme
proLocol hosL porL
1he proLocol//hosLporL of Lhe proxy separaLed lnLo dlscreLe elemenLs
username password
1hese elemenLs appear as a palr denoLlng Lhe logln and password requlred Lo
auLhenLlcaLe Lo Lhls proxy server
nonroxyPosLs
1hls ls a llsL of hosLs whlch should noL be proxled 1he dellmlLer of Lhe llsL ls Lhe
expecLed Lype of Lhe proxy server Lhe example above ls plpe dellmlLed comma
dellmlLed ls also common
1S2S rof||es
1he proflle elemenL ln Lhe settloqsxml ls a LruncaLed verslon of Lhe pomxml proflle elemenL lL
conslsLs of Lhe acLlvaLlon reposlLorles plugln8eposlLorles and properLles elemenLs 1he proflle
elemenLs only lnclude Lhese four elemenLs because Lhey concern Lhemselves wlLh Lhe bulld
sysLem as a whole (whlch ls Lhe role of Lhe settloqsxml flle) noL abouL lndlvldual pro[ecL ob[ecL
model seLLlngs
lf a proflle ls acLlve from seLLlngs lLs values wlll overrlde any equlvalenL proflles whlch maLchlng
ldenLlflers ln a CM or ptofllesxml flle
1S26 Act|vat|on
AcLlvaLlons are Lhe key of a proflle Llke Lhe CM's proflles Lhe power of a proflle comes from
lLs ablllLy Lo modlfy some values only under cerLaln clrcumsLances Lhose clrcumsLances are
speclfled vla an acLlvaLlon elemenL
Def|n|ng Act|vat|on arameters |n sett|ngsxm|
seLLlngs xmlnshLLp//mavenapacheorg/SL11lnCS/100
xmlnsxslhLLp//wwww3org/2001/xMLSchemalnsLance
xslschemaLocaLlonhLLp//mavenapacheorg/SL11lnCS/100
hLLp//mavenapacheorg/xsd/seLLlngs100xsd

proflles
proflle
ldLesL/ld
acLlvaLlon
acLlve8yuefaulLfalse/acLlve8yuefaulL
[dk13/[dk
os
nameWlndows x/name
famllyWlndows/famlly
archx86/arch
verslon312600/verslon
/os
properLy
namemavenverslon/name
value203/value
/properLy
flle
exlsLs$basedlr/flle2properLles/exlsLs
mlsslng$basedlr/flle1properLles/mlsslng
/flle
/acLlvaLlon

/proflle
/proflles

/seLLlngs
AcLlvaLlon occurs when all speclfled crlLerla have been meL Lhough noL all are requlred aL once
[dk
acLlvaLlon has a bullL ln !avacenLrlc check ln Lhe [dk elemenL 1hls wlll acLlvaLe lf Lhe
LesL ls run under a [dk verslon number LhaL maLches Lhe preflx glven ln Lhe above
example 130_06 wlll maLch
os
1he os elemenL can deflne some operaLlng sysLem speclflc properLles shown above
properLy
1he proflle wlll acLlvaLe lf Maven deLecLs a properLy (a value whlch can be dereferenced
wlLhln Lhe CM by oome) of Lhe correspondlng namevalue palr
flle
llnally a glven fllename may acLlvaLe Lhe proflle by Lhe exlsLence of a flle or lf lL ls
mlsslng
1he acLlvaLlon elemenL ls noL Lhe only way LhaL a proflle may be acLlvaLed 1he settloqsxml flle's
acLlveroflle elemenL may conLaln Lhe proflle's ld 1hey may also be acLlvaLed expllclLly Lhrough
Lhe command llne vla a comma separaLed llsL afLer Lhe flag (eg LesL)
1o see whlch proflle wlll acLlvaLe ln a cerLaln bulld use Lhe mavenhelpplugln
mvn helpacLlveproflles
1S27 ropert|es
Maven properLles are value placeholder llke properLles ln AnL 1helr values are accesslble
anywhere wlLhln a CM by uslng Lhe noLaLlon O where x ls Lhe properLy 1hey come ln flve
dlfferenL sLyles all accesslble from Lhe seLLlngsxml flle
+env+x
reflxlng a varlable wlLh env wlll reLurn Lhe shell's envlronmenL varlable lor example
eovlA1n conLalns Lhe $paLh envlronmenL varlable (A1P ln Wlndows)
+pro[ecL+x
A doLnoLaLed () paLh ln Lhe CM wlll conLaln Lhe correspondlng elemenLs value
+seLLlngs+x
A doLnoLaLed () paLh ln Lhe settloqsxml wlll conLaln Lhe correspondlng elemenLs value
!ava sysLem properLles
All properLles accesslble vla [avalangSysLemgeLroperLles() are avallable as CM properLles
such as ovobome
x
SeL wlLhln a properLles elemenL or an exLernal flle Lhe value may be used as somevot
Sett|ng the 5userinsto// property |n sett|ngsxm|
seLLlngs xmlnshLLp//mavenapacheorg/SL11lnCS/100
xmlnsxslhLLp//wwww3org/2001/xMLSchemalnsLance
xslschemaLocaLlonhLLp//mavenapacheorg/SL11lnCS/100
hLLp//mavenapacheorg/xsd/seLLlngs100xsd

proflles
proflle

properLles
userlnsLall$userdlr/ourpro[ecL/userlnsLall
/properLles

/proflle
/proflles

/seLLlngs
1he properLy setlostoll ls accesslble from a CM lf Lhls proflle ls acLlve
1S28 kepos|tor|es
8eposlLorles are remoLe collecLlons of pro[ecLs from whlch Maven uses Lo populaLe Lhe local
reposlLory of Lhe bulld sysLem lL ls from Lhls local reposlLory LhaL Maven calls lL pluglns and
dependencles ulfferenL remoLe reposlLorles may conLaln dlfferenL pro[ecLs and under Lhe
acLlve proflle Lhey may be searched for a maLchlng release or snapshoL arLlfacL
kepos|tory Conf|gurat|on |n sett|ngsxm|
seLLlngs xmlnshLLp//mavenapacheorg/SL11lnCS/100
xmlnsxslhLLp//wwww3org/2001/xMLSchemalnsLance
xslschemaLocaLlonhLLp//mavenapacheorg/SL11lnCS/100
hLLp//mavenapacheorg/xsd/seLLlngs100xsd

proflles
proflle

reposlLorles
reposlLory
ldcodehausSnapshoLs/ld
nameCodehaus SnapshoLs/name
releases
enabledfalse/enabled
updaLeollcyalways/updaLeollcy
checksumollcywarn/checksumollcy
/releases
snapshoLs
enabledLrue/enabled
updaLeollcynever/updaLeollcy
checksumollcyfall/checksumollcy
/snapshoLs
urlhLLp//snapshoLsmavencodehausorg/maven2/url
layouLdefaulL/layouL
/reposlLory
/reposlLorles
plugln8eposlLorles

/plugln8eposlLorles

/proflle
/proflles

/seLLlngs
releases snapshoLs
1hese are Lhe pollcles for each Lype of arLlfacL 8elease or snapshoL WlLh Lhese Lwo
seLs a CM has Lhe power Lo alLer Lhe pollcles for each Lype lndependenL of Lhe oLher
wlLhln a slngle reposlLory lor example one may declde Lo enable only snapshoL
downloads posslbly for developmenL purposes
enabled
Lrue or false for wheLher Lhls reposlLory ls enabled for Lhe respecLlve Lype (releases or
snapshoLs)
updaLeollcy
1hls elemenL speclfles how ofLen updaLes should aLLempL Lo occur Maven wlll compare
Lhe local CMs LlmesLamp Lo Lhe remoLe 1he cholces are always dally (defaulL) lnLervalx
(where x ls an lnLeger ln mlnuLes) or never
checksumollcy
When Maven deploys flles Lo Lhe reposlLory lL also deploys correspondlng checksum
flles ?our opLlons are Lo lgnore fall or warn on mlsslng or lncorrecL checksums
layouL
ln Lhe above descrlpLlon of reposlLorles lL was menLloned LhaL Lhey all follow a common
layouL 1hls ls mosLly correcL Maven 2 has a defaulL layouL for lLs reposlLorles however
Maven 1x had a dlfferenL layouL use Lhls elemenL Lo speclfy whlch lf lL ls defaulL or
legacy lf you are upgradlng from Maven 1 Lo Maven 2 and you wanL Lo use Lhe same
reposlLory whlch was used ln your Maven 1 bulld llsL Lhe layouL as legacy
1S29 |ug|n kepos|tor|es
1he sLrucLure of Lhe plugln8eposlLorles elemenL block ls slmllar Lo Lhe reposlLorles elemenL 1he
plugln8eposlLory elemenLs each speclfy a remoLe locaLlon of where Maven can flnd pluglns
arLlfacLs
|ug|n kepos|tor|es |n sett|ngsxm|
seLLlngs xmlnshLLp//mavenapacheorg/SL11lnCS/100
xmlnsxslhLLp//wwww3org/2001/xMLSchemalnsLance
xslschemaLocaLlonhLLp//mavenapacheorg/SL11lnCS/100
hLLp//mavenapacheorg/xsd/seLLlngs100xsd

proflles
proflle

reposlLorles

/reposlLorles
plugln8eposlLorles
plugln8eposlLory
ldcodehausSnapshoLs/ld
nameCodehaus SnapshoLs/name
releases
enabledfalse/enabled
updaLeollcyalways/updaLeollcy
checksumollcywarn/checksumollcy
/releases
snapshoLs
enabledLrue/enabled
updaLeollcynever/updaLeollcy
checksumollcyfall/checksumollcy
/snapshoLs
urlhLLp//snapshoLsmavencodehausorg/maven2/url
layouLdefaulL/layouL
/plugln8eposlLory
/plugln8eposlLorles

/proflle
/proflles

/seLLlngs
1S210 Act|ve rof||es
Sett|ng act|ve prof||es |n sett|ngsxm|
seLLlngs xmlnshLLp//mavenapacheorg/SL11lnCS/100
xmlnsxslhLLp//wwww3org/2001/xMLSchemalnsLance
xslschemaLocaLlonhLLp//mavenapacheorg/SL11lnCS/100
hLLp//mavenapacheorg/xsd/seLLlngs100xsd

acLlveroflles
acLlveroflleenvLesL/acLlveroflle
/acLlveroflles
/seLLlngs
1he flnal plece of Lhe settloqsxml puzzle ls Lhe acLlveroflles elemenL 1hls conLalns a seL of
acLlveroflle elemenLs whlch each have a value of a proflle ld Any proflle ld deflned as an
acLlveroflle wlll be acLlve regardless of any envlronmenL seLLlngs lf no maLchlng proflle ls found
noLhlng wlll happen lor example lf envLesL ls an acLlveroflle a proflle ln a pomxml (or ptofllexml
wlLh a correspondlng ld lL wlll be acLlve lf no such proflle ls found Lhen execuLlon wlll conLlnue
as normal
1S211 Lncrypt|ng asswords |n Maven Sett|ngs
Cnce you sLarL Lo use Maven Lo deploy sofLware Lo remoLe reposlLorles and Lo lnLeracL wlLh
source conLrol sysLems dlrecLly you wlll sLarL Lo collecL a number of passwords ln your Maven
SeLLlngs and wlLhouL a mechanlsm for encrypLlng Lhese passwords a developer's
/m2/settloqsxml wlll qulckly become a securlLy rlsk as lL wlll conLaln plalnLexL passwords Lo
source conLrol and reposlLory managers Maven 21 lnLroduced a faclllLy Lo encrypL passwords
ln a user's Maven SeLLlngs (/m2/settloqsxml) 1o do Lhls you musL flrsL creaLe a masLer
password and sLore Lhls masLer password ln a sectltysettloqsxml flle ln /m2/settloqs
sectltyxml ?ou can Lhen use Lhls masLer password Lo encrypL passwords sLored ln Maven
SeLLlngs (/m2/settloqsxml)
1o lllusLraLe Lhls feaLure conslder Lhe process Maven uses Lo reLrleve an unencrypLed server
password for a user's Maven SeLLlngs as shown ln llgure 131 SLorlng unencrypLed asswords
ln Maven SeLLlngs" A user wlll reference a named server uslng an ldenLlfler ln a pro[ecL's CM
Maven looks for a maLchlng server ln Maven SeLLlngs When lL flnds a maLchlng server elemenL
ln Maven SeLLlngs Maven wlll Lhen use Lhe password assoclaLed wlLh LhaL server elemenL and
send Lhls password along Lo Lhe server 1he password ls sLored as plalnLexL ln
/m2/settloqsxml and lL ls readlly avallable Lo anyone who has read access Lo Lhls flle

I|gure 1S1 Stor|ng Unencrypted asswords |n Maven Sett|ngs

nexL conslder Lhe process Maven uses Lo supporL encrypLed passwords as shown ln
llgure 132 SLorlng LncrypLed asswords ln Maven SeLLlngs"

I|gure 1S2 Stor|ng Lncrypted asswords |n Maven Sett|ngs

1o conflgure encrypLed passwords creaLe a masLer password by runnlng mvn emp or mvn
encrypLmasLerpassword followed by your masLer password
$ mvn emp mypassword
rs8368!cqoLPZqLZ081v841lspmCux1Ln8/vvsgaCw
Maven prlnLs ouL an encrypLed copy of Lhe password Lo sLandard ouL Copy Lhls encrypLed
password and pasLe lL lnLo a /m2/settloqssectltyxml flle as shown ln
sett|ngssecur|tyxm| w|th Master assword
seLLlngsSecurlLy
masLerrs8368!cqoLPZqLZ081v841lspmCux1Ln8/vvsgaCw/masLer
/seLLlngsSecurlLy
AfLer you have creaLed a masLer password you can Lhen encrypL passwords for use ln your
Maven SeLLlngs 1o encrypL a password wlLh Lhe masLer password run mvn ep or mvn encrypL
password Assume LhaL you have a reposlLory manager and you need Lo send a username of
deploymenL and a password of quallLyll8S1 1o encrypL Lhls parLlcular password you would
run Lhe followlng command
$ mvn ep quallLyll8S1
uMrbLCLf/vCPnc0W2x49Cab73[9LS1wlM3mg2LCrCzl
AL Lhls polnL copy Lhe encrypLed password prlnLed from Lhe ouLpuL of mvn ep and pasLe lL lnLo
your Maven SeLLlngs
Stor|ng an Lncrypted assword |n Maven Sett|ngs (]m2]sett|ngsxm|)
seLLlngs
servers
server
ldnexus/ld
usernamedeploymenL/username
passworduMrbLCLf/vCPnc0W2x49Cab73[9LS1wlM3mg2LCrCzl/password
/server
/servers

/seLLlngs
When you run a Maven bulld LhaL needs Lo lnLeracL wlLh Lhe reposlLory manager Maven wlll
reLrleve Lhe MasLer password from Lhe /m2/settloqssectltyxml flle and use Lhls masLer
password Lo decrypL Lhe password sLored ln your /m2/settloqsxml flle Maven wlll Lhen send
Lhe decrypLed password Lo Lhe server
WhaL does Lhls buy you? lL allows you Lo avold sLorlng your passwords ln /m2/settloqsxml as
plalnLexL passwords provldlng you wlLh Lhe peace of mlnd LhaL your crlLlcal passwords are noL
belng sLored unproLecLed ln a Maven SeLLlngs flle noLe LhaL Lhls feaLure does noL provlde for
encrypLlon of Lhe password whlle lL ls belng senL Lo Lhe remoLe server An enLerprlslng aLLacker
could sLlll capLure Lhe password uslng a neLwork analysls Lool
lor an exLra level of securlLy you can encourage your developers Lo sLore Lhe encrypLed masLer
password on a removable sLorage devlce llke a uS8 hard drlve uslng Lhls meLhod a developer
would plug a removable drlve lnLo a worksLaLlon when she wanLed Lo perform a deploymenL or
lnLeracL wlLh a remoLe server 1o supporL Lhls your /m2/settloqssectltyxml flle would
conLaln a reference Lo Lhe locaLlon of Lhe settloqssectltyxml flle uslng Lhe relocaLlon elemenL
Conf|gur|ng ke|ocat|on of the Master assword
seLLlngsSecurlLy
relocaLlon/volumes/usbkey/seLLlngssecurlLyxml/relocaLlon
/seLLlngsSecurlLy
1he developer would Lhen sLore Lhe settloqssectltyxml flle aL /volmes/sbkey/settloqs
sectltyxml whlch would only be avallable lf Lhe developer were slLLlng aL Lhe worksLaLlon
Chapter 16 Append|x Sun Spec|f|cat|on A|ternat|ves
1he Apache Ceronlmo pro[ecL malnLalns lmplemenLaLlons of varlous enLerprlse !ava
speclflcaLlons 1able 161 AlLernaLe Spec lmplemenLaLlons ArLlfacLs" llsLs Lhe arLlfacLld and
arLlfacL verslon for all of Lhe speclflcaLlons lmplemenLed by Lhe Ceronlmo pro[ecL 1o use one of
Lhese dependencles use a groupld of orgapachegeronlmospecs locaLe Lhe verslon of Lhe
SpeclflcaLlon you wanL Lo use and reference Lhe dependency wlLh Lhe ArLlfacL ld and ArLlfacL
verslon llsLed ln 1able 161 AlLernaLe Spec lmplemenLaLlons ArLlfacLs"
Note
All arLlfacLs ln 1able 161 AlLernaLe Spec lmplemenLaLlons ArLlfacLs" have a groupld of
orgapachegeronlmospecs
1ab|e 161 A|ternate Spec Imp|ementat|ons Art|facts
SpeclflcaLlon Spec verslon ArLlfacL ld ArLlfacL verslon
AcLlvaLlon 102 geronlmoacLlvaLlon_102_spec 12
AcLlvaLlon 11 geronlmoacLlvaLlon_11_spec 101
AcLlvaLlon 10 geronlmoacLlvaLlon_10_spec 11
Common! 11 geronlmocommon[_11_spec 10
Corba 23 geronlmocorba_23_spec 11
Corba 30 geronlmocorba_30_spec 12
L!8 21 geronlmoe[b_21_spec 11
L!8 30 geronlmoe[b_30_spec 10
LL 10 geronlmoel_10_spec 10
lnLercepLor 30 geronlmolnLercepLor_30_spec 10
!2LL ConnecLor 13 geronlmo[2eeconnecLor_13_spec 111
!2LL ueploymenL 11 geronlmo[2eedeploymenL_11_spec 11
!2LL !ACC 10 geronlmo[2ee[acc_10_spec 111
!2LL ManagemenL 10 geronlmo[2eemanagemenL_10_spec 11
!2LL ManagemenL 11 geronlmo[2eemanagemenL_11_spec 10
!2LL 14 geronlmo[2ee_14_spec 11
!ACC 11 geronlmo[acc_11_spec 10
!LL ueploymenL 11M83 geronlmo[avaeedeploymenL_11M83_spec 10
!avaMall 131 geronlmo[avamall_131_spec 13
!avaMall 14 geronlmo[avamall_14_spec 12
!Ax8 10 geronlmo[axr_10_spec 11
!Ax8C 11 geronlmo[axrpc_11_spec 11
!MS 11 geronlmo[ms_11_spec 11
!A 30 geronlmo[pa_30_spec 11
!S 20 geronlmo[sp_20_spec 11
!S 21 geronlmo[sp_21_spec 10
!1A 1018 geronlmo[La_1018_spec 111
!1A 11 geronlmo[La_11_spec 11
Cname 11 geronlmoqname_11_spec 11
SAA! 11 geronlmosaa[_11_spec 11
ServleL 24 geronlmoservleL_24_spec 111
ServleL 23 geronlmoservleL_23_spec 111
S1ax Al 10 geronlmosLaxapl_10_spec 101
WS MeLadaLa 20 geronlmowsmeLadaLa_20_spec 111

Note
1he verslon numbers ln Lhe ArLlfacL verslon column may be ouL of daLe by Lhe Llme you read
Lhls book 1o check on Lhe verslon number vlslL
hLLp//repo1mavenorg/maven2/org/apache/geronlmo/specs/ ln a web browser and cllck on
Lhe arLlfacLld you wanL Lo add Choose Lhe hlghesL verslon of Lhe spec you wanL Lo depend
upon
1o lllusLraLe how one would use 1able 161 AlLernaLe Spec lmplemenLaLlons ArLlfacLs" lf we
wanLed Lo wrlLe some code ln our pro[ecL whlch lnLeracLed wlLh Lhe !1A 1018 speclflcaLlon
we would need Lo add Lhe followlng dependency Lo our pro[ecL
Add|ng I1A 1018 to a Maven ro[ect
dependency
groupldorgapachegeronlmospecs/groupld
arLlfacLldgeronlmo[La_1018_spec/arLlfacLld
verslon111/verslon
/dependency
noLlce how Lhe verslon of Lhe arLlfacL lsn'L golng Lo llne up wlLh Lhe verslon of Lhe
speclflcaLlonLhe prevlous dependency conflguraLlon adds verslon 1018 of Lhe !1A
speclflcaLlon uslng Lhe arLlfacL verslon of 111 8e aware of Lhls when dependlng on Lhe
alLernaLe Ceronlmo lmplemenLaLlons and always double check LhaL you are uslng Lhe laLesL
arLlfacL verslon number for your speclflcaLlons
Chapter 17 Creat|ve Commons L|cense
1hls work ls llcensed under a CreaLlve Commons ALLrlbuLlonnoncommerclalno uerlvaLlve
Works 30 unlLed SLaLes llcense lor more lnformaLlon abouL Lhls llcense see
hLLp//creaLlvecommonsorg/llcenses/byncnd/30/us/ ?ou are free Lo share copy dlsLrlbuLe
dlsplay and perform Lhe work under Lhe followlng condlLlons
O ?ou musL aLLrlbuLe Lhe work Lo SonaLype lnc wlLh a llnk Lo hLLp//wwwsonaLypecom
O ?ou may noL use Lhls work for commerclal purposes
O ?ou may noL alLer Lransform or bulld upon Lhls work
lf you redlsLrlbuLe Lhls work on a web page you musL lnclude Lhe followlng llnk wlLh Lhe u8L ln
Lhe abouL aLLrlbuLe llsLed on a slngle llne (remove Lhe backslashes and [oln all u8L parameLers)
dlv xmlnscchLLp//creaLlvecommonsorg/ns#
abouLhLLp//creaLlvecommonsorg/llcense/resulLsone?q_12q_11
fleld_commerclalnfleld_derlvaLlvesnfleld_[urlsdlcLlonus
fleld_formaLSLllllmagefleld_workLlLle8eposlLory3A+ManagemenL
fleld_aLLrlbuLe_Lo_nameSonaLype2C+lnc
fleld_aLLrlbuLe_Lo_urlhLLp3A2l2lwwwsonaLypecom
fleld_sourceurlhLLp3A2l2lwwwsonaLypecom2lbook
langen_uSlanguageen_uSn_quesLlons3
a relccaLLrlbuLlonu8L properLyccaLLrlbuLlonname
hrefhLLp//wwwsonaLypecomSonaLype lnc/a /
a relllcense
hrefhLLp//creaLlvecommonsorg/llcenses/byncnd/30/us/
CC 8?nCnu 30/a
/dlv
When downloaded or dlsLrlbuLed ln a [urlsdlcLlon oLher Lhan Lhe unlLed SLaLes of Amerlca Lhls
work shall be covered by Lhe approprlaLe porLed verslon of CreaLlve Commons ALLrlbuLlon
noncommerclalno uerlvaLlve Works 30 llcense for Lhe speclflc [urlsdlcLlon lf Lhe CreaLlve
Commons ALLrlbuLlonnoncommerclalno uerlvaLlve Works verslon 30 llcense ls noL avallable
for a speclflc [urlsdlcLlon Lhls work shall be covered under Lhe CreaLlve Commons ALLrlbuLlon
noncommerclalno uerlvaLe Works verslon 23 llcense for Lhe [urlsdlcLlon ln whlch Lhe work
was downloaded or dlsLrlbuLed A comprehenslve llsL of [urlsdlcLlons for whlch a CreaLlve
Commons llcense ls avallable can be found on Lhe CreaLlve Commons lnLernaLlonal web slLe aL
hLLp//creaLlvecommonsorg/lnLernaLlonal
lf no porLed verslon of Lhe CreaLlve Commons llcense exlsLs for a parLlcular [urlsdlcLlon Lhls
work shall be covered by Lhe generlc unporLed CreaLlve Commons ALLrlbuLlonnoncommerclal
no uerlvaLlve Works verslon 30 llcense avallable from
hLLp//creaLlvecommonsorg/llcenses/byncnd/30/

Das könnte Ihnen auch gefallen