Force Repository Update with Maven - Baeldung

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

Therefore, the download into our local repository is necessary to access all needed code at ... Could not resolve dependencies for project . StartHereCourses ▼▲ RESTwithSpring ThecanonicalreferenceforbuildingaproductiongradeAPIwithSpring LearnSpringSecurity ▼▲ THEuniqueSpringSecurityeducationifyou’reworkingwithJavatoday LearnSpringSecurityCore FocusontheCoreofSpringSecurity5 LearnSpringSecurityOAuth FocusonthenewOAuth2stackinSpringSecurity5 LearnSpring Fromnoexperiencetoactuallybuildingstuff​ LearnSpringDataJPA ThefullguidetopersistencewithSpringDataJPA Guides ▼▲ Persistence ThePersistencewithSpringguides REST TheguidesonbuildingRESTAPIswithSpring Security TheSpringSecurityguides About ▼▲ FullArchive Thehighleveloverviewofallthearticlesonthesite. BaeldungEbooks DiscoverallofoureBooks AboutBaeldung AboutBaeldung. GenericTop GetstartedwithSpring5andSpringBoot2,throughtheLearnSpringcourse: >>CHECKOUTTHECOURSE 1.Overview Inthistutorial,we'lllearnhowtoforce-updatealocalMavenrepositorywhenitbecomescorrupted.Toaccomplishthis,we'lluseastraightforwardexampletounderstandwhyarepositorycanbecomecorruptedandhowtofixit. 2.Prerequisites Tolearnandrunthecommandsinthistutorial,weneedtouseaSpringInitializrprojectandhaveaJDKandMaveninstalled. 3.MavenRepositoryStructure Mavensavesallthedependenciesofprojectsinthe.m2folder.Forexample,inthefollowingimage,wecanobservethestructureofMavenrepositories: Aswecansee,Mavendownloadsalldependenciesundertherepositoryfolder.Therefore,thedownloadintoourlocalrepositoryisnecessarytoaccessallneededcodeatruntime. 4.DownloadingDependencies WeknowthatMavenworksbasedonthepom.xmlfileconfigurations.WhenMavenexecutesthispom.xml file,thedependencies willbe downloaded fromacentral Mavenrepository andputintoyourlocal Mavenrepository.Ifwealreadyhavethedependenciesinourlocalrepository, Maven willnot downloadthem. Thedownloadhappenswhenweexecutethefollowingcommands: mvnpackage mvninstall Bothoftheaboveincludeexecutingthefollowingcommand: mvndependency:resolve  Therefore,wecansolelyresolvethedependencieswithoutusingapackageorinstallbyjustrunningthedependency:resolvecommand. 5.CorruptedDependencies Whiledownloadingthedependencies,anetworkglitchcanhappen,resultingincorrupteddependencies.Theinterrupteddependencydownloadistheleadingcauseofcorruption.Mavenwilldisplayamessageaccordingly: Couldnotresolvedependenciesforproject... Let'sseenexthowwecansolvethisissue. 6.AutomaticallyFixingtheCorruptedDependencies Mavenusuallydisplaysthecorrupteddependencywhenitnotifiesthatthebuildfailed: Couldnottransferartifact[artifact-name-here]... Tofixthis,wecanhaveautomaticormanualapproaches. Additionally,weshouldrunanyrepositoryupdateindebugmode,addingthe-Xoptionafter-Utohaveabetterpictureofwhathappensduringtheupdate. 6.1.ForceUpdateAllSNAPSHOTDependencies Asweknowalready,Mavenwillnotdownloadexistingdependenciesagain.Therefore,toforceMaventoupdateallcorruptedSNAPSHOTdependencies,weshouldaddinourcommandthe -U/–update-snapshotsoption: mvnpackage-U mvninstall-U Still,wehavetorememberthattheoptiondoesnotre-downloadaSNAPSHOTdependencyifMavenalreadydownloadeditandifthechecksumisthesame. Thiswillalsopackageorinstallourprojectnext.Finally,we'lllearnhowtoupdatetherepositorywithoutincludingthecurrentworkingproject. 6.2.DependencyResolveGoal WecantellMaventoresolveourdependenciesandupdatesnapshotswithoutanypackageorinstallcommand.Forthispurpose,we'llusethedependency:resolvegoal,byincludingthe-U option: mvndependency:resolve-U 6.3.PurgeLocalRepositoryGoal Weknowthat-U  justre-downloadsthecorruptedSNAPSHOTdependencies.Asaresult,inthecaseofcorruptedlocalreleasedependencies,wemightneeddeepercommands.Forthispurpose,weshoulduse: mvndependency:purge-local-repository Thepurposeofthedependency:purge-local-repository istopurge(deleteandoptionallyre-resolve)artifactsfromthelocalMavenrepository.Bydefault,artifactswillbere-resolved. 6.4.PurgeLocalRepositoryOptions Thepurgelocalrepositorycanbeconfiguredtorunforonlyacertaingroupofdependenciesbyspecifyingthe“groupId”fortheresolutionFuzzinessoption,andtheexactgroupIDtosearchforusingtheincludeoption: mvndependency:purge-local-repository-Dinclude:org.slf4j-DresolutionFuzziness=groupId-Dverbose TheresolutionFuzzinessoptioncanhavethevalues:version,artifactId,groupId,file. Theexampleabovewillsearchforandpurgeallartifactsintheorg.slf4jgroup.We'vealsosettheverboseoptionsowecanseedetailedlogsoftheartifactsdeleted. Ifanyfilesthatmatchtheconditionarefound,thelogwilldisplayatextlike: Deleting2transitivedependenciesforproject[...]withartifactgroupIdresolutionfuzziness [INFO]Purgingartifact:org.slf4j:jul-to-slf4j:jar:1.7.31 Purgingartifact:org.slf4j:slf4j-api:jar:1.7.31 Notethattospecifytheartifactsincludedorexcludedfordeletionorrefresh,wecanusetheoptionsinclude/exclude: mvndependency:purge-local-repository-Dinclude=com.yyy.projectA:projectB-Dexclude=com.yyy.projectA:projectC 7.ManuallyDeletingtheRepository Whereasthe-Uoptionandpurge-local-repositorymightresolvethecorrupteddependencieswithoutrefreshingallofthem,themanualdeleteofthe.m2localrepositorywillcauseaforcedre-downloadofalldependencies. Thiscanbeusefulwhenhavingoldandmaybecorrupteddependencies.Thenasimplere-packageorre-installshoulddothejob.Moreover,wecanusethedependency:resolveoptiontosolvethedependenciesofourprojectsolely. 8.Conclusion Inthistutorial,wediscussedtheoptionsandgoalsofMaventhatforciblyupdatesourlocalrepository. ThesamplesusedaresimpleMavencommandsthatcanbeusedonanyprojectwithaproperpom.xmlconfigured. Genericbottom GetstartedwithSpring5andSpringBoot2,throughtheLearnSpringcourse: >>CHECKOUTTHECOURSE Genericfooterbanner LearningtobuildyourAPIwithSpring? DownloadtheE-book 2Comments Oldest Newest InlineFeedbacks Viewallcomments ViewComments LoadMoreComments Commentsareclosedonthisarticle! Genericsidebarbanner BuildingaRESTAPIwithSpring5? DownloadtheE-book wpDiscuzInsert



請為這篇文章評分?