{"id":690,"date":"2021-05-08T15:10:53","date_gmt":"2021-05-08T15:10:53","guid":{"rendered":"http:\/\/www.scmgalaxy.com\/tutorials\/2017\/07\/29\/how-to-configure-sonatype-nexus-repository-with-maven\/"},"modified":"2021-10-28T05:53:50","modified_gmt":"2021-10-28T05:53:50","slug":"how-to-configure-sonatype-nexus-repository-with-maven","status":"publish","type":"post","link":"https:\/\/www.devopsschool.com\/blog\/how-to-configure-sonatype-nexus-repository-with-maven\/","title":{"rendered":"How to configure Sonatype Nexus repository to download maven dependency?"},"content":{"rendered":"<h3>How to configure Sonatype Nexus repository with Maven?<\/h3>\n<div>Automatic dependencies is one of the powerful feature of Apache maven and its one of the reason Maven is very popular in developer community. Maven resolve the dependent library from local repository which is again connected with central repository or remote repository. thus we can say that Maven has 3 kinds of repository concept.<\/div>\n<ul>\n<li>Local repostory e.g $USER_HOME\/.m2<\/li>\n<li>Central repostory e.g http:\/\/repo.maven.apache.org\/maven2\/<\/li>\n<li>Private repostory e.g Sonatype Nexus, Artifactory, Archiva etc.<\/li>\n<\/ul>\n<div>The diagram shown below represent how maven resolve the dependendency.<\/div>\n<p><strong>High Level Interaction between Local Repository, Central Repository and Remote Repository.<\/strong><\/p>\n<p><img loading=\"lazy\" decoding=\"async\" class=\" size-full wp-image-683\" src=\"http:\/\/www.scmgalaxy.com\/tutorials\/wp-content\/uploads\/2017\/07\/maven-nexus-repository-flow4.png\" alt=\"\" width=\"498\" height=\"209\" srcset=\"https:\/\/www.devopsschool.com\/blog\/wp-content\/uploads\/2017\/07\/maven-nexus-repository-flow4.png 498w, https:\/\/www.devopsschool.com\/blog\/wp-content\/uploads\/2017\/07\/maven-nexus-repository-flow4-300x126.png 300w\" sizes=\"auto, (max-width: 498px) 100vw, 498px\" \/><br>\n<strong>Dependency Management using Local Repository, Central Repository and Remote Repository.<br>\n<img loading=\"lazy\" decoding=\"async\" class=\" size-full wp-image-684\" src=\"http:\/\/www.scmgalaxy.com\/tutorials\/wp-content\/uploads\/2017\/07\/maven-nexus-repository-flow5.png\" alt=\"\" width=\"892\" height=\"428\" srcset=\"https:\/\/www.devopsschool.com\/blog\/wp-content\/uploads\/2017\/07\/maven-nexus-repository-flow5.png 1600w, https:\/\/www.devopsschool.com\/blog\/wp-content\/uploads\/2017\/07\/maven-nexus-repository-flow5-300x144.png 300w, https:\/\/www.devopsschool.com\/blog\/wp-content\/uploads\/2017\/07\/maven-nexus-repository-flow5-768x368.png 768w, https:\/\/www.devopsschool.com\/blog\/wp-content\/uploads\/2017\/07\/maven-nexus-repository-flow5-1024x491.png 1024w\" sizes=\"auto, (max-width: 892px) 100vw, 892px\" \/><br>\nThis is How maven interact with Repository!<\/strong><\/p>\n<p><img loading=\"lazy\" decoding=\"async\" class=\" size-full wp-image-685\" src=\"http:\/\/www.scmgalaxy.com\/tutorials\/wp-content\/uploads\/2017\/07\/maven-nexus-repository-flow3.jpg\" alt=\"\" width=\"620\" height=\"280\" srcset=\"https:\/\/www.devopsschool.com\/blog\/wp-content\/uploads\/2017\/07\/maven-nexus-repository-flow3.jpg 620w, https:\/\/www.devopsschool.com\/blog\/wp-content\/uploads\/2017\/07\/maven-nexus-repository-flow3-300x135.jpg 300w\" sizes=\"auto, (max-width: 620px) 100vw, 620px\" \/><br>\n<img loading=\"lazy\" decoding=\"async\" class=\" size-full wp-image-686\" src=\"http:\/\/www.scmgalaxy.com\/tutorials\/wp-content\/uploads\/2017\/07\/maven-nexus-repository-flow2.jpg\" alt=\"\" width=\"456\" height=\"270\" srcset=\"https:\/\/www.devopsschool.com\/blog\/wp-content\/uploads\/2017\/07\/maven-nexus-repository-flow2.jpg 456w, https:\/\/www.devopsschool.com\/blog\/wp-content\/uploads\/2017\/07\/maven-nexus-repository-flow2-300x178.jpg 300w\" sizes=\"auto, (max-width: 456px) 100vw, 456px\" \/><\/p>\n<h4>This is a diagram which shows the define flow in which maven try to resolve the dependency.<\/h4>\n<p><img loading=\"lazy\" decoding=\"async\" class=\" size-full wp-image-687\" src=\"http:\/\/www.scmgalaxy.com\/tutorials\/wp-content\/uploads\/2017\/07\/maven-nexus-repository-flow1.png\" alt=\"\" width=\"656\" height=\"487\" srcset=\"https:\/\/www.devopsschool.com\/blog\/wp-content\/uploads\/2017\/07\/maven-nexus-repository-flow1.png 656w, https:\/\/www.devopsschool.com\/blog\/wp-content\/uploads\/2017\/07\/maven-nexus-repository-flow1-300x223.png 300w\" sizes=\"auto, (max-width: 656px) 100vw, 656px\" \/><\/p>\n<h4>Now, We have understood that Central rrepository is in built but next questions is, How to inform the maven about the location of remote repository? In order to configure maven with remote repostory, in our case SonaType Nexus, we need to configuring host machine setting.xml and projects pom.xml to use your Nexus repos.<\/h4>\n<h4>Put this in your ~\/.m2\/settings.xml file. This will configure the credentials to publish to your hosted repos, and will tell your mvn to use your repo as a mirror of central:<\/h4>\n<p><img loading=\"lazy\" decoding=\"async\" class=\" size-full wp-image-688\" src=\"http:\/\/www.scmgalaxy.com\/tutorials\/wp-content\/uploads\/2017\/07\/maven-nexus-repository-flow6.jpg\" alt=\"\" width=\"594\" height=\"622\" srcset=\"https:\/\/www.devopsschool.com\/blog\/wp-content\/uploads\/2017\/07\/maven-nexus-repository-flow6.jpg 594w, https:\/\/www.devopsschool.com\/blog\/wp-content\/uploads\/2017\/07\/maven-nexus-repository-flow6-286x300.jpg 286w\" sizes=\"auto, (max-width: 594px) 100vw, 594px\" \/><\/p>\n<h4>And now configure your projects.<\/h4>\n<h4>If you want only to download dependencies from Nexus, put this in the pom.xml:<\/h4>\n<p><img loading=\"lazy\" decoding=\"async\" class=\" size-full wp-image-689\" src=\"http:\/\/www.scmgalaxy.com\/tutorials\/wp-content\/uploads\/2017\/07\/maven-nexus-repository-flow7.jpg\" alt=\"\" width=\"608\" height=\"259\" srcset=\"https:\/\/www.devopsschool.com\/blog\/wp-content\/uploads\/2017\/07\/maven-nexus-repository-flow7.jpg 608w, https:\/\/www.devopsschool.com\/blog\/wp-content\/uploads\/2017\/07\/maven-nexus-repository-flow7-300x128.jpg 300w\" sizes=\"auto, (max-width: 608px) 100vw, 608px\" \/><\/p>\n<h4>and<\/h4>\n<h4>Add the following at the end of setting.xml<\/h4>\n<h4>&lt;activeProfiles&gt;<\/h4>\n<h4>&nbsp; &nbsp; &lt;!&#8211;make the profile active all the time &#8211;&gt;<\/h4>\n<h4>&nbsp; &nbsp; &lt;activeProfile&gt;nexus&lt;\/activeProfile&gt;<\/h4>\n<h4>&nbsp; &lt;\/activeProfiles&gt;<\/h4>\n<h4>Reference<\/h4>\n<h4><a href=\"https:\/\/maven.apache.org\/guides\/mini\/guide-mirror-settings.html\" target=\"_blank\" rel=\"noopener\">https:\/\/maven.apache.org\/guides\/mini\/guide-mirror-settings.html<\/a><\/h4>\n<h4><\/h4>\n\n<div class=\"epyt-gallery\" data-currpage=\"1\" id=\"epyt_gallery_44884\"><iframe loading=\"lazy\"  id=\"_ytid_40848\"  width=\"760\" height=\"427\"  data-origwidth=\"760\" data-origheight=\"427\" src=\"https:\/\/www.youtube.com\/embed\/?enablejsapi=1&#038;autoplay=0&#038;cc_load_policy=0&#038;cc_lang_pref=&#038;iv_load_policy=1&#038;loop=0&#038;rel=1&#038;fs=1&#038;playsinline=0&#038;autohide=2&#038;theme=dark&#038;color=red&#038;controls=1&#038;disablekb=0&#038;\" class=\"__youtube_prefs__  no-lazyload\" title=\"YouTube player\"  data-epytgalleryid=\"epyt_gallery_44884\"  allow=\"fullscreen; accelerometer; autoplay; clipboard-write; encrypted-media; gyroscope; picture-in-picture; web-share\" referrerpolicy=\"strict-origin-when-cross-origin\" allowfullscreen data-no-lazy=\"1\" data-skipgform_ajax_framebjll=\"\"><\/iframe><div class=\"epyt-gallery-list\"><div>Sorry, there was a YouTube error.<\/div><\/div><\/div>","protected":false},"excerpt":{"rendered":"<p>How to configure Sonatype Nexus repository with Maven? Automatic dependencies is one of the powerful feature of Apache maven and its one of the reason Maven is very popular in&#8230; <\/p>\n","protected":false},"author":1,"featured_media":2748,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"_joinchat":[],"footnotes":""},"categories":[157],"tags":[282,545,161,571,570,569],"class_list":["post-690","post","type-post","status-publish","format-standard","has-post-thumbnail","hentry","category-sonatype-nexus","tag-configuration","tag-how","tag-maven","tag-repository","tag-sonatype-nexus","tag-sonatype-nexus-tutorials"],"_links":{"self":[{"href":"https:\/\/www.devopsschool.com\/blog\/wp-json\/wp\/v2\/posts\/690","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/www.devopsschool.com\/blog\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/www.devopsschool.com\/blog\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/www.devopsschool.com\/blog\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/www.devopsschool.com\/blog\/wp-json\/wp\/v2\/comments?post=690"}],"version-history":[{"count":12,"href":"https:\/\/www.devopsschool.com\/blog\/wp-json\/wp\/v2\/posts\/690\/revisions"}],"predecessor-version":[{"id":24393,"href":"https:\/\/www.devopsschool.com\/blog\/wp-json\/wp\/v2\/posts\/690\/revisions\/24393"}],"wp:featuredmedia":[{"embeddable":true,"href":"https:\/\/www.devopsschool.com\/blog\/wp-json\/wp\/v2\/media\/2748"}],"wp:attachment":[{"href":"https:\/\/www.devopsschool.com\/blog\/wp-json\/wp\/v2\/media?parent=690"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/www.devopsschool.com\/blog\/wp-json\/wp\/v2\/categories?post=690"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/www.devopsschool.com\/blog\/wp-json\/wp\/v2\/tags?post=690"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}