1. Proxy configuration
To configure basic proxy in maven we have to edit the file settings.xml in our ‘<user_home>/.m2’ directory. If there is no file, we can copy it from the global settings folder ‘<maven_home>/conf’.
<!-- 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>
-->
We can define an <id> to the proxy to change between proxies, and deactivate our original entry by setting <active> to false.
2. Securing our configuration
The simple configuration of maven proxy it is use an plain text password, so if you prefer to hide your password we can encrypt our passwrods.
Creating a master password
Before to encrypt our proxy password we must define a master password in maven by entering it the following command:
mvn --encrypt-master-password 'masterpassword'
{w3uV4IJ4DjUHFYKFJWEMqIVNWKAw1Q6oXXaNfYXqiKc=}
In case your encryptec password has any curly braces we should escape with \ before it to avoid some problems.
Next step is creating a settings-security.xml file in our .m2 directory:
<settingsSecurity>
<master>{w3uV4IJ4DjUHFYKFJWEMqIVNWKAw1Q6oXXaNfYXqiKc=}</master>
</settingsSecurity>
Encrypting proxy passwords
After creating a master password, we can encrypt our proxy passord by running the following command:
mvn --encrypt-password mypassword
{ff+jjK6rE90HSJuOgExvNbOLDeC6A2miebZUJzDE9XA=}
To end we have to edit the proxy section in our settings.xml file, and put in our encrypted password:
<proxies>
<proxy>
<id>MyProxy</id>
<host>proxy.domain.com</host>
<port>80</port>
<username>username</username>
<password>{ff+jjK6rE90HSJuOgExvNbOLDeC6A2miebZUJzDE9XA=}</password>
</proxy>
</proxies>