6

I have a few personal projects and few corporate ones. The corporate projects use a mirrored corporate SVN repo for maven dependencies. I would like to configure my settings.xml in such a way that the dependencies are first checked against my corporate mirror. Only when the dependencies are not found here (for my personal projects) then it should check against the original "central" repo that is mirrored by my corporate repo. Is this possible. Below is a snippet of what I have right now but it doesn't hit the "central" repo when required. Thanks.

<servers>
    <server>
        <id>central-mirror</id>
        <username>myusername</username>
        <password>mypassword</password>
        <filePermissions>664</filePermissions>
        <directoryPermissions>775</directoryPermissions>
        <configuration></configuration>
    </server>
</servers>

<mirrors>
    <mirror>
        <id>central-mirror</id>
        <url>https://url.to.my/mirror</url>
        <mirrorOf>central</mirrorOf>
    </mirror>
</mirrors>


<proxies>
    <proxy>
    <id>proxy</id>
    <active>true</active>
    <protocol>http</protocol>
    <host>my.corporate.proxy</host>
    <port>8080</port>
    <nonProxyHosts>localhost|*.my.corporate.proxy</nonProxyHosts>
</proxy>

zoostar
  • 249
  • 1
  • 3
  • 11

2 Answers2

10

Ok after some trial and error I finally figured out how to do this. I am hoping this will help out many others. Below is my updated settings.xml. For any project in my Eclipse, maven first tries to download libs from my corporate mirror. Only if it can't find it there, it gets it from central repo.

<servers>
    <server>
        <id>central-mirror</id>
        <username>myusername</username>
        <password>mypassword</password>
        <filePermissions>664</filePermissions>
        <directoryPermissions>775</directoryPermissions>
        <configuration></configuration>
    </server>
</servers>

<mirrors>
    <mirror>
        <id>central-mirror</id>
        <url>https://url.to.my/mirror</url>
        <mirrorOf>*,!central</mirrorOf>
    </mirror>
</mirrors>


<proxies>
    <proxy>
    <id>proxy</id>
    <active>true</active>
    <protocol>http</protocol>
    <host>my.corporate.proxy</host>
    <port>8080</port>
    <nonProxyHosts>localhost|*.my.corporate.proxy</nonProxyHosts>
</proxy>

<profiles>
  <profile>
    <activeByDefault>true</activeByDefault>
    <repositories>
        <repository>
            <id>central-mirror</id>
            <url>https://url.to.my/mirror</url>
        </repository>
    </repositories>
  </profile>
</profiles
Community
  • 1
  • 1
zoostar
  • 249
  • 1
  • 3
  • 11
  • 3
    Could you explain this a little? Why is there only one mirror and repo when you need two mirrors? Why is there a server defined in this? – thisdotnull Feb 18 '16 at 10:42
  • By default maven uses official mirror, `*,!central` set as default will match `no official` repo, server is defined for user account such as when you need uploading – qtopierw Jun 14 '19 at 03:33
  • 1
    To enable 3rd party mirror, change `*,!central` to `central` – qtopierw Jun 14 '19 at 07:49
0

well I have a similar scenario where if an artifact is not available in corporate repo then it should default to global repo.

I made two changes in my original settings.xml-

  1. define a <proxy> tag for your network
  2. If mirrorOf property is * then change it to repo ID
thisdotnull
  • 812
  • 1
  • 7
  • 20