Introduction to Repositories - Apache Maven

文章推薦指數: 80 %
投票人數:10人

In general, you should not need to do anything with the local repository on a ... by a project declaring a dependency that is not present in the local ... IntroductiontoRepositories ArtifactRepositories ArepositoryinMavenholdsbuildartifactsanddependenciesofvaryingtypes. Thereareexactlytwotypesofrepositories:localandremote: thelocalrepositoryisadirectoryonthecomputerwhereMavenruns.Itcachesremotedownloadsandcontainstemporarybuildartifactsthatyouhavenotyetreleased. remoterepositoriesrefertoanyothertypeofrepository,accessedbyavarietyofprotocolssuchasfile://andhttps://.Theserepositoriesmightbeatrulyremoterepositorysetupbyathirdpartytoprovidetheirartifactsfordownloading(forexample,repo.maven.apache.org).Other"remote"repositoriesmaybeinternalrepositoriessetuponafileorHTTPserverwithinyourcompany,usedtoshareprivateartifactsbetweendevelopmentteamsandforreleases. Localandremoterepositoriesarestructuredthesamewaysothatscriptscanrunoneitherside,ortheycanbesyncedforofflineuse.ThelayoutoftherepositoriesiscompletelytransparenttotheMavenuser,however. UsingRepositories Ingeneral,youshouldnotneedtodoanythingwiththelocalrepositoryonaregularbasis,exceptcleanitoutifyouareshortondiskspace(oreraseitcompletelyifyouarewillingtodownloadeverythingagain). Fortheremoterepositories,theyareusedforbothdownloadinganduploading(ifyouhavethepermissiontodoso). DownloadingfromaRemoteRepository DownloadinginMavenistriggeredbyaprojectdeclaringadependencythatisnotpresentinthelocalrepository(orforaSNAPSHOT,whentheremoterepositorycontainsonethatisnewer).Bydefault,Mavenwilldownloadfromthecentralrepository. Tooverridethis,youneedtospecifyamirrorasshowninUsingMirrorsforRepositories. Youcansetthisinyoursettings.xmlfiletogloballyuseacertainmirror.However,itiscommonforaprojecttocustomisetherepositoryinitspom.xmlandthatyoursettingwilltakeprecedence.Ifdependenciesarenotbeingfound,checkthatyouhavenotoverriddentheremoterepository. Formoreinformationondependencies,seeDependencyMechanism. UsingMirrorsfortheCentralRepository ThereareseveralofficialCentralrepositoriesgeographicallydistributed.Youcanmakechangestoyoursettings.xmlfiletouseoneormoremirrors.InstructionsforthiscanbefoundintheguideUsingMirrorsforRepositories. BuildingOffline Ifyouaretemporarilydisconnectedfromtheinternetandyouneedtobuildyourprojectsoffline,youcanusetheofflineswitchontheCLI: mvn-opackage Manypluginshonortheofflinesettinganddonotperformanyoperationsthatconnecttotheinternet.SomeexamplesareresolvingJavadoclinksandlinkcheckingthesite. UploadingtoaRemoteRepository Whilethisispossibleforanytypeofremoterepository,youmusthavethepermissiontodoso.TohavesomeoneuploadtotheCentralMavenrepository,seeRepositoryCenter. InternalRepositories WhenusingMaven,particularlyinacorporateenvironment,connectingtotheinternettodownloaddependenciesisnotacceptableforsecurity,speedorbandwidthreasons.Forthatreason,itisdesirabletosetupaninternalrepositorytohouseacopyofartifacts,andtopublishprivateartifactsto. SuchaninternalrepositorycanbedownloadedusingHTTPorthefilesystem(withafile://URL),anduploadedtousingSCP,FTP,orafilecopy. AsfarasMavenisconcerned,thereisnothingspecialaboutthisrepository:itisanotherremoterepositorythatcontainsartifactstodownloadtoauser'slocalcache,andisapublishdestinationforartifactreleases. Additionally,youmaywanttosharetherepositoryserverwithyourgeneratedprojectsites.Formoreinformationoncreatinganddeployingsites,seeCreatingaSite. SettinguptheInternalRepository Tosetupaninternalrepositoryjustrequiresthatyouhaveaplacetoputit,andthencopyrequiredartifactsthereusingthesamelayoutasinaremoterepositorysuchasrepo.maven.apache.org. Itisnotrecommendedthatyouscrapeorrsync://afullcopyofcentralasthereisalargeamountofdatathereanddoingsowillgetyoubanned.YoucanuseaprogramsuchasthosedescribedontheRepositoryManagementpagetorunyourinternalrepository'sserver,downloadfromtheinternetasrequired,andthenholdtheartifactsinyourinternalrepositoryforfasterdownloadinglater. Theotheroptionsavailablearetomanuallydownloadandvetreleases,thencopythemtotheinternalrepository,ortohaveMavendownloadthemforauser,andmanuallyuploadthevettedartifactstotheinternalrepositorywhichisusedforreleases.Thisstepistheonlyoneavailableforartifactswherethelicenseforbidstheirdistributionautomatically,suchasseveralJ2EEJARsprovidedbySun.RefertotheGuidetocopingwithSUNJARsdocumentformoreinformation. ItshouldbenotedthatMavenintendstoincludeenhancedsupportforsuchfeaturesinthefuture,includingclickthroughlicensesondownloading,andverificationofsignatures. UsingtheInternalRepository Usingtheinternalrepositoryisquitesimple.Simplymakeachangetoaddarepositorieselement: ... my-internal-site https://myserver/repo ... Ifyourinternalrepositoryrequiresauthentication,theidelementcanbeusedinyoursettingsfiletospecifylogininformation. DeployingtotheInternalRepository Oneofthemostimportantreasonstohaveoneormoreinternalrepositoriesistobeabletopublishyourownprivatereleases. Topublishtotherepository,youwillneedtohaveaccessviaoneofSCP,SFTP,FTP,WebDAV,orthefilesystem.Connectivityisaccomplishedwiththevariouswagons.Somewagonsmayneedtobeaddedasextensiontoyourbuild.



請為這篇文章評分?