0

I'm running into what I think is a catch-22 situation the way my settings.xml file is set up.

Currently, when I'm in the office, I use our Nexus as our principal source. All repos are mirrored to Nexus, and Nexus, in turn, is a proxy for Central. Everything works fine. I am able to download artifacts from central, and those local to Nexus.

However, when I am out of the office, I no longer have access to the Nexus server. So I changed my settings.xml file to disable the mirror to central. However, now maven complains that it is unable to find local artifacts that are hosted on my Nexus even though they exist in my local m2 repo.

I know that Maven 3 tracks the location from which the artifact was downloaded with the _maven.repositories file (see this post as well as other resources). However, I am not sure how I am supposed to configure my issue such that I can move around like this.

When I am out of the office, I don't have access to my Nexus, but want to continue using my local repo for artifacts that were previously cached. But I do not want to turn Maven offline altogether as I need to d/l other artifacts from Central to continue working.

settings.xml when at office

   <mirrors>
        <mirror>
            <id>nexus</id>
            <mirrorOf>*</mirrorOf>
            <url>https://nexus.local/nexus/content/groups/public/</url>
        </mirror>
    </mirrors>

settings.xml when out of office:

  <mirrors>
        <mirror>
            <id>nexus</id>
            <mirrorOf>*,!central</mirrorOf>
            <url>https://nexus.local/nexus/content/groups/public/</url>
        </mirror>
    </mirrors>

Should my mirror be configured differently? Is there a better way to set this up? I realize that I can just delete my _maven.repositories file, but that is not particularly practical nor, I'm sure, advisable.

Community
  • 1
  • 1
Eric B.
  • 23,425
  • 50
  • 169
  • 316
  • Why do you change the settings.xml when you leave the office? Let them be as they are. If that Nexus is not reachable from abroad it should not affect the use of the local Maven repository. – hotzst Oct 03 '15 at 05:58
  • In a similar scenario I solved my problem by deleting the _maven.repositories file. This is the info that helped me to fix my problem: http://www.aljoscha-rittner.de/blog/archive/2013/09/10/build-offline-with-maven/ Maybe this could be applied to yours (double check before deleting! ;) )? – Robert Reiner Oct 03 '15 at 07:38
  • @hotzst Because if I don't, then I have no access to any repos and cannot use anything that I don't have in my local repo. – Eric B. Oct 03 '15 at 15:37
  • @RobertReiner I know, but was looking for a cleaner solution than that. Was hoping that something existed already for this scenario – Eric B. Oct 03 '15 at 15:38
  • [MNG-5185](https://issues.apache.org/jira/browse/MNG-5185) is tracking the problem (referenced from the blog article) and it is not yet resolved. So it seemed to me that there is still no clean way to do this. ... – Robert Reiner Oct 04 '15 at 09:30
  • I assume that 'most close to clean' :) is to have a separate local repository where you remove only the _maven.repositories files to the artifacts of your company (I haven't actually tried this selective removing, though). It seems to me that there is no reason to have these files, if I assume that you can be sure of the 'originality' of these artifacts (as far as I understand the explanation of Stephen Connolly for the intention of this feature). – Robert Reiner Oct 04 '15 at 09:30
  • But maybe there is another reason you do not think removing the file is a viable workaround? May I ask - just out of curiosity - which version of Maven you are using? (Sorry because of three comments, but I hadn't the time to get it shorter ...) – Robert Reiner Oct 04 '15 at 09:30
  • @RoberReiner - It's not that removing it is not a viable workaround; it's just that it is error prone, and easily forgotten every time I switch back and forth. Plus, a nuissance! :) I was hoping that someone had come up with a nifty workaround. I'm running Maven 3.2.5. The only thing I found so far was to dump my mirror definition, and redefine Central to be my public proxy on my nexus server in a profile. When I'm at the office, I enable the profile, and disable it when I am out of the office. But still quite kludgy. – Eric B. Oct 05 '15 at 01:04

0 Answers0