Introduction to Repositories - Apache Maven
文章推薦指數: 80 %
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:
延伸文章資訊
- 1Introduction to Repositories - Apache Maven
In general, you should not need to do anything with the local repository on a ... by a project de...
- 2maven系列--Could not resolve dependencies问题的解决
mvn compile 编译问题 Could not resolve dependencies for project xxxxxx Failed to collect dependencies...
- 3How to Fix Maven Artifacts Could not be Resolved Error ...
I executed below command to install it in my localhost maven repo and everything worked. ... Coul...
- 4Maven Repo: Could not resolve dependencies ... - GitLab
The problem is while building the parent project, it fails to find the dependency. Below are the ...
- 5dependency resolution - Maven fails to find local artifact
This means that there's no local repository used when resolving dependencies (though your install...