How to download maven dependencies behind organization proxy
Introduction
Whether you’re a Software Developer or an Automation Engineer, Maven is a widely used build tool today. One common challenge in some environments is the inability to download Maven dependencies due to organizational proxies. In this article, I’ll share a quick guide on how to download Maven dependencies behind your organization’s proxy.
Proxy Configuration
Let’s understand how to setup proxy configuration. This configuration can be done in settings.xml file.
- Open your
settings.xml
file located in<user_home>/.m2
directory. If the file does not exist, you can create it. - Add the following
<proxies>
configuration inside the<settings>
element, replacingproxy.example.com
and8080
with your server’s hostname and port:
<proxies>
<proxy>
<id>example-proxy</id>
<active>true</active>
<protocol>http</protocol>
<host>proxy.example.com</host>
<port>8080</port>
<!-- Optional: Proxy username and password -->
<!--<username>proxy-username</username>-->
<!--<password>proxy-password</password>-->
<!--<nonProxyHosts>localhost|127.0.0.1</nonProxyHosts>-->
</proxy>
</proxies>
If your organization requires authentication, uncomment the <username>
and <password>
tags and provide your credentials. Additionally, you can specify hosts that should bypass the proxy in the <nonProxyHosts>
tag.
Test the Configuration:
To test the proxy configuration, run a Maven command such as mvn clean install
for a Maven project. Maven should now be able to download dependencies through the proxy.