How to configure Maven to not use proxy server - maven

I am trying to configure Maven to not use a proxy server. This turns out to be a lot of work. Somewhere Maven has read some proxy information which it keeps on using.
I tried the following already.
in the terminal unset http_proxy and https_proxy
I did not have a settings.xml. I added one and added a proxy config to it with active is false
In settings.xml active = true and nonProxyHosts = *
I remove proxy settings from /etc/environment
I don't want to install a local proxy server just to get this working, is there another way to tell Maven not to use a proxy server.

The first step is to ask Maven to show you what configuration it sees/uses. Use the Help plugin for this: mvn help:effective-pom shows you the complete POM that Maven will use and help:effective-settings will do the same for the settings.xml.
Now you can see whether there are any proxy settings in those outputs, just to make sure the Maven universe is clean. My guess is that someone changes the global/default settings.xml from the conf folder of your Maven installation.
Afterwards, you need to check the proxy options which Java uses. Check your environment and the file $HOME/.mavenrc

Related

Maven & proxy settings

I'm using the Maven template from To Be Continuous in order to build and deploy into Gitlab Packages.
My corporate network requires proxy to access Maven registry (Maven central) but my runner has direct access to Gitlab.
I set the proxy preferences via http_proxy (and related) var env.
The TBC template values the JVM system properties.
The mvn package succeed, but mvn deploy fails.
I add the proxy settings inside settings.xml.
The mvn package succeed, but mvn deploy fails.
My understanding: one plugin detects the proxy but ignores the exclusions.
I add a step to unset the var env just before mvn command, keeping the JVM system properties set by TBC template.
The both commands succeed.
What's wrong?
Edit: related to an issue: https://gitlab.com/to-be-continuous/maven/-/issues/31

Maven dependency not getting resolved in Intellij

I have Maven setup and updated settings.xml with proxy settings. While working on project it is unable to load any dependency in IntelliJ.
I verified all the config with one of my friend and its working in his machine correctly. Please help.
Ensure that you are pointing to correct settings.xml in the configuration of intellij
Go to-->File-->Settings-->Build,Execution,Deployment-->Mavan
and validate user settings file and local repository file, if its having different details update the path or replace the file.

using Maven setting.xml to pass build arguments to fabric8io/docker-maven-plugin

we are using fabric8io/docker-maven-plugin to build dockers in our application.
because we are sitting behind a corporate firewall we need to setup a proxy for our build.
as part of our docker files, we defined ARG HTTPS_PROXY.
now to build our docker we need to pass the proxy argument using the mvn command line as:
mvn clean install -Ddocker.buildArg.http_proxy=<proxy>
-Ddocker.buildArg.https_proxy=<proxy>
I am looking for a way to set up this configuration in the maven setting xml.
to make it easier.
any suggestions will be appreciated

maven If mirror fails, fall back to original

I have a sonatype-nexus configured in lan for maven and the is connected using the mirror configuration in settings.xml shown below.
<mirrors>
<mirror>
<mirrorOf>*</mirrorOf>
<name>nexus.sb.karmalab.net</name>
<url>http://<lan_repo>/remote-repos</url>
</mirror>
This setting creates an issue if the is down.
Is there some option to configure the mirror to connect to the remote repo id the local lookup fails.
Maven Jira has an issue for this feature, but it was closed years ago without being addressed.
I have a similiar setup, where I have a Nexus3 Repository Manager setup on my lan, and ran into the same problem when I turned off my Nexus3 Repository Manager.
Based on what I read the issue linked by Igor Dvorhak was closed and the topic seems to not have been brought up recently.
Anyhow, here is a workaround that worked for me.
You get two locations to place settings.xml
User Level ... normally provided in ${user.home}/.m2/settings.xml.
Global level ... normally provided in ${maven.conf}/settings.xml.
If a User Level settings.xml is defined it takes precedence over Global level but also you can override it by giving the maven command the -s flag with the path to your settings.xml.
You can learn more about settings.xml here: Maven - Settings Reference
So what I did is setup the mirror at the User Level, but when the repository the mirror is pointed at was down (i.e. our own setup lan repository), I instructed the mvn command to use the global settings.xml which is set to go to central by default.
I happened to have an environment variable called M2_HOME in my ${user.home}/.bashrc file when I was setting up apache maven, So I am going to reuse that environment variable to construct the path. Then there is a conf folder inside the apache maven installation folder that contains the global settings.xml.
Finally here is the command to workaround the offline mirror site.
mvn clean install -s $M2_HOME/conf/settings.xml
Note: Your paths may be different if your working on a Windows OS.

How do I set up Spring and Maven environment for working offline?

I need to set up Spring and Maven for working offline. I am working with Spring Tool Suite.What environment variables do I need to configure besides M2 env var? When I try to add dependencies in pom.xml, and type springframework, nothing comes up in the search bar. I get "Core exception Could not calculate build plan Plugin org.apache.maven.plugins:m. I understand STS uses web services to locate the jars, so how do I configure Spring and Maven to work offline? Thank you.
Maven uses central repositoty to update dependencies via internet if you want run it offline you need to configure you local repository.See Setting local Maven repository
This is something that you will find very difficult or near impossible unless you somehow get all the relevant jars from spring and place them in your .m2 repo directory.
Your question has been asked a number of times on here ...
Have a look through these 2 questions which I assume is exactly what you have encountered.
Question 1
Question 2
Also one last note ...
After you setup your variables did you restart your PC I know sometimes I forget to do this when updating environment variables.
Before you go offline run the following:
mvn dependency:go-offline
That will download all your dependencies and plugins that you need to build your project into ~/.m2/repository.
Once you've run that you can now build your project offline using the '-o' flag:
mvn install -o
It's also possible to configure the offline mode globally by setting the offline property in the ~/.m2/settings.xml file:
true

Resources