Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Make Maven Proxy/Server settings configurable based on location?

So I'm not sure what the best way to accomplish this is, but basically I have a laptop that I use at work for Maven projects. It works fine when I'm at work, but as soon as I walk out of the door of their corporate proxy and maven server, I often have to do alot of hand-fudging of the settings.xml file when I'm at home if I'm not VPN'ed in:

  • We have a corporate-installed Maven Repository proxy server to store some of our own artifacts and handle being the middle-man for our commonly used artifacts.
  • We have an http proxy that we use for connecting to the outside world.

Both configurations have been handled by my settings.xml file for setting a single Nexus group and maven proxies. If I'm not connected to the VPN while away from the office, I have to muck around with the settings.xml each time I'm not on it, then switch it back when I am on it.

What solutions have anyone else found to handle this? I've been trying profiles to manage the proxy, but I can't seem to get it to work correctly, and it's starting to look pretty ugly. Are there some settings configurations that can detect when I'm not behind the proxy at work and not use the corporate proxy server or Maven server?

like image 294
Nick Klauer Avatar asked Mar 01 '10 05:03

Nick Klauer


People also ask

How do I setup a proxy server address?

Select the Start button, then select Settings > Network & Internet > Proxy. Under Manual proxy setup, turn on Use a proxy server. Do the following: In the Address and Port boxes, enter the proxy server name or IP address and port (optional) in the respective boxes.

Where is proxy settings xml?

Proxy Configuration xml usually found in our '<user_home>/. m2′ directory.

What is the use of settings xml in .m2 folder?

Maven provides a settings file, settings. xml, which allows us to specify which local and remote repositories it will use. We can also use it to store settings that we don't want in our source code, such as credentials.


1 Answers

While I can think of some profile based solution to handle the proxy (basically, reading the <active> value from a property defined in a profile), this wouldn't be fully automated (the profile activation do not support network based stuff) unless you can find a file that is present or not depending on your location (in which case, you could use an existing/missing file trigger but this is kinda hacky). Anyway, this would solve only one part of the problem because mirrors can't be declared in profiles (see MNG-3525).

So, instead of trying to control this with a profile, my suggestion would be to use two settings.xml and to pass your settings-home.xml file with the -s command line option when you're at home.

Another option would be to automate the changes in your settings.xml with a script (Groovy would be a good choice as someone reported in MNG-3525).

like image 197
Pascal Thivent Avatar answered Sep 25 '22 10:09

Pascal Thivent