How to let Maven download from Nexus but bypass it for external jars - maven

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.

Related

How to make maven search for artifacts in local repository

I have a project that worked fine on another pc. And now i'm trying to run it on another pc. There is no acces to proxy. And after any action it says that
couldn't transfer artifact. no route to host
But i have all depandencies in local repository, maven just doesn't want to take it from there. Is there a way to make him take all artifacts from local repo first?
There must be a version difference in the artifacts you have in your local repository and the ones mentioned in pom.xml
Your error : couldn't transfer artifact. no route to host
is because you have'nt added proxy to your pom. eg :
<proxies>
<!-- proxy
| Specification for one proxy, to be used in connecting to the network.
|
-->
<proxy>
<id>optional</id>
<active>true</active>
<protocol>http</protocol>
<username>username</username>
<password>yourpassword</password>
<host>yourhost#host.com</host>
<port>80</port>
<nonProxyHosts>local.net|some.host.com</nonProxyHosts>
</proxy>
</proxies>
Add it to the settings.xml file in conf folder of maven and try again

Not able to create maven project under eclipse mars even after setting the proxy

Hi Everyone ,
I am new to Maven environment . Tried all possibilities of enabling the proxy under settings.xml .But no use. Since the maven is integrated in mars I couldn't find the settings.xml and created my own under .m2 . And also tried with the external maven also .But no results .
Below is my settings.xml .
<settings>
<proxies>
<proxy>
<active>true</active>
<protocol>http</protocol>
<host>hostname</host>
<port>port</port>
<username></username>
<password></password>
<nonProxyHosts></nonProxyHosts>
</proxy>
</proxies>
</settings>
The failed request from before has been cached by Maven. You need to run the command with the -U flag to retry. (Or wait until the caching has expired...)

Understand the use of mirror and repositories

I have a Nexus OSS server configured as my Repository. I'm trying to configure the settings.xml to this server and central:
<settings>
<servers>
<server>
<id>nexus</id>
<username>admin</username>
<password>admin123</password>
</server>
</servers>
<mirrors>
<mirror>
<!--This sends everything else to /public -->
<id>nexus</id>
<mirrorOf>*</mirrorOf>
<url>http://localhost:8081/nexus/content/groups/public</url>
</mirror>
</mirrors>
</settings>
In my Nexus Repo (http://localhost:8081/nexus/content/groups/public/) i just have the following files (i uploaded the mylib.jar in thirdparty repo):
archetype-catalog.xml Fri May 27 12:17:45 BRT 2016 25
But when i tried to mvn:install the maven don't find my JAR in Thrid Part repository, i got the error:
The POM for br.com:mylib:jar:2.0 is missing, no dependency information available
Your mirror settings will work. I almost said they were "fine" but that's an overstatement. They should work for the situation you have presented.
IF:
You succesfully loaded br.com:mylib:2.0 into the thirdparty repo (are you sure? It should probably be com.br, but what do I know...)
AND:
You can find it in the thirdparty repo within the nexus browser
THEN:
You should be able to resolve it without specifying any additional repositories.
Sounds like your config of Nexus doesn't have your third-party library in the groups/public group, which is what you're using as your mirror source for central.
Make sure that public includes thirdparty
I use Nexus 3 which, by default, doesn't include any such repository.

mave 3.2 not able to access local nexus instance return 502 code

While accessing local nexus repository which is in local host the return code is 502.
pom.xml looks something like this
<repositories>
<repository>
<id>nexus</id>
<name>nexusPublic</name>
<url>http://localhost:8081/nexus/content/groups/public/</url>
</repository>
</repositories>
To OP and anyone who may have got here through google (just like me):
I had the same issue, the project I entered used some artifact from the repository on our server (via Archiva). I was able to reach the jar from browser, but Maven was not able to find it.
The problem was that my company uses proxy and it was impossible to connect to company's server through it's own proxy. I added <nonProxyHosts>servername.dev.company.com</nonProxyHosts> to my Maven configuration (.m2/settings.xml).
According to this answer, in your case it would be <nonProxyHosts>*localhost*</nonProxyHosts>.
Question is already answered but let me write full xml configuration file:
.m2/settings.xml
<settings>
<proxies>
<proxy>
<id>proxy_http</id>
<active>true</active>
<protocol>http</protocol>
<host>proxy host</host>
<port>porxy port</port>
<nonProxyHosts>local.net|host_1|host_2|host_3</nonProxyHosts>
</proxy>
</proxies>
</settings>

maven failure to resolve archetype ear-jee5

I am trying to create an EAR maven module project (in eclipse) with ear-jee5 as the archetype. It fails with the following error.
Could not resolve archetype org.codehaus.mojo.archetypes:ear-jee5:1.3 from any of the configured repositories.
Could not resolve artifact
Missing org.codehaus.mojo.archetypes:ear-jee5:pom:1.3
Could someone please help me resolve this error or show me an alternate way to create the project structure for Maven EAR module?
Thanks.
Apparently, the failure seems to be because I am behind a proxy/firewall at office. The solution is add proxy configurations or add repository mirrors not blocked by firewall in your settings.xml.
hope this helps someone.
Add proxy
<proxies>
<!-- proxy
| Specification for one proxy, to be used in connecting to the network.
|
<proxy>
<id>optional</id>
<active>true</active>
<protocol>http</protocol>
<username>proxyuser</username>
<password>proxypass</password>
<host>proxy.host.net</host>
<port>80</port>
<nonProxyHosts>local.net|some.host.com</nonProxyHosts>
</proxy>
-->
</proxies>
or mirrors
<mirrors>
<!-- mirror
| Specifies a repository mirror site to use instead of a given repository. The repository that
| this mirror serves has an ID that matches the mirrorOf element of this mirror. IDs are used
| for inheritance and direct lookup purposes, and must be unique across the set of mirrors.
|
<mirror>
<id>mirrorId</id>
<mirrorOf>repositoryId</mirrorOf>
<name>Human Readable Name for this Mirror.</name>
<url>http://my.repository.com/repo/path</url>
</mirror>
<mirrors>
Thanks

Resources