I understand Nexus is supposed to download the external dependencies, but the company Nexus server (over which I have no control) cannot access the internet or download external jars.
As a workaround I have 2x settings.xml files which I manually switch. One settings.xml use the corporate Nexus server for internal jars and the other uses the company proxy to download external dependencies from the default Maven repositories. Once all the dependencies are in my local Maven repo compilings works.
settings.xml for Nexus (excluding proxies)
<settings>
<mirrors>
<mirror>
<id>some-repo-mirror</id>
<mirrorOf>*</mirrorOf>
<url>https://brokennexus/repository/maven-public/</url>
</mirror>
</mirrors>
<servers>
<server>
<id>some-repo-mirror</id>
<username>me</username>
<password>secret</password>
</server>
</servers>
</settings>
settings.xml for internet (excluding mirrors and servers)
<settings>
<proxies>
<proxy>
<id>company-proxy-http</id>
<active>true</active>
<protocol>http</protocol>
<username>me</username>
<password>secret</password>
<host>proxy.server</host>
<port>8080</port>
</proxy>
<proxy>
<id>company-proxy-https</id>
<active>true</active>
<protocol>https</protocol>
<username>me</username>
<password>secret</password>
<host>proxy.server</host>
<port>8080</port>
</proxy>
</proxies>
</settings>
Both files works on their own, but I cannot figure out how to combine them into one.
Is there a way to configure maven in such a way that if the company Nexus cannot resolve a dependency it would fall back and attempt to download from an external repo through the company's internet proxy or the other way around so that I do not have to switch between the two settings.xml files?
You can configure the proxy in your "normal"
settings.xml
and exclude your Nexus as nonProxyHost:https://maven.apache.org/guides/mini/guide-proxies.html
Furthermore, you need to change the mirror configuration
<mirrorOf>*</mirrorOf>
to something like<mirrorOf>*,!central</mirrorOf>
to be able to connect MavenCentral (and other repositories directly).Of course, the preferred solution would be to talk to the admin if they can add the external repositories to the company Nexus.