Reputation: 31
I've run into a situation where configuring Nexus as a Mirror for everything doesn't quite suit my needs. My Nexus repository is behind a VPN. If I can't access the Nexus repository, I can't build anything because it's configured as a Mirror. What if I want to build a project that has no dependencies on my Nexus repository yet I can't access it? This would build fine by simply using the Central repository but it won't look there because of the Mirror.
Does anyone have any ideas on how to get around this? I think ideally I'd like to look at Nexus first but if it's not accessible I'd like to look at the Central repository. I'm also open to any other suggestions for achieving the same goal that anyone may have.
Upvotes: 0
Views: 2142
Reputation: 29912
The best approach for this kind of requirement is to run Nexus locally on your development machine.
Its easy to install and run and you can just always point to it.
Configure it to proxy your corporate Nexus and Central.
Then when you are off the VPN .. the corporate proxy repo will just be unreachable but you still get anything else just fine. Nexus manages it all for you.
I have been doing this for years and it allows me to switch to different contexts all the time very easily. It is a bit of a standard practice for many Maven users in fact and should be for other tools that use remote repositories like Gradle or SBT as well. Makes things a LOT easier.
Upvotes: 2
Reputation: 414
you need to configure multiple repositories
http://maven.apache.org/guides/mini/guide-multiple-repositories.html
maven-3.0.4\conf\settings.xml file could be configured this way:
<?xml version="1.0" encoding="UTF-8"?>
<settings xmlns="http://maven.apache.org/SETTINGS/1.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://maven.apache.org/SETTINGS/1.0.0 http://maven.apache.org/xsd/settings-1.0.0.xsd">
<pluginGroups />
<proxies />
<servers>
<server>
<!-- local repository have restricted access -->
<id>central</id>
<username>myusername</username>
<password>mypassword</password>
</server>
<server>
<id>LocalRepository</id>
<username>myusername</username>
<password>mypassword</password>
</server>
</servers>
<mirrors>
<mirror>
<id>central</id>
<mirrorOf>external:*</mirrorOf>
<name>Central</name>
<url>url to repository</url>
</mirror>
<mirror>
<id>LocalRepository</id>
<mirrorOf>LocalRepository</mirrorOf>
<name>repository</name>
<url>url to repository</url>
</mirror>
</mirrors>
<profiles>
<profile>
<id>central</id>
<repositories>
<repository>
<id>central</id>
<name>Central</name>
<url>http://central/</url>
<releases>
<enabled>true</enabled>
</releases>
</repository>
<repository>
<id>LocalRepository</id>
<name>specific repository</name>
<url>repository URL</url>
</repository>
</repositories>
</profile>
</profiles>
<activeProfiles>
<activeProfile>central</activeProfile>
</activeProfiles>
</settings>
Upvotes: 2