Using Maven and Gradle through proxy

Because of my working environment, I have to set up Gradle and Maven to use a proxy server without password authentication. Only setting up the operating system to use a proxy is not sufficient, as I cannot establish network communication using Maven or Gradle. How can I configure the tools to communicate through a proxy?
1 answer

Both Maven and Gradle have to be configured individually to communicate through a proxy.

For configuring Maven, the settings.xml file in the {user.home}/.m2/ directory has to be edited. Create a new settings.xml if it does not exist. Within that file add the following tags to allow Maven to communicate through a proxy:

<settings>
<proxies>
<proxy>
<id>example</id>
<active>true</active>
<protocol>http</protocol>
<host>{IP-address of the proxy}</host>
<port>{port of the proxy}</port>
<nonProxyHosts>{excluded IP adresses}</nonProxyHosts>
</proxy>
</proxies>
</settings>

To allow communication using the https protocol, use <protocol>https</protocol> or add an additional proxy configuration for https.

To configure Gradle to communicate through a proxy, the gradle.properties file located in the {user.home}/.gradle/ directory is modified. As with Maven, if it file does not exists, create a new one. Within that file, the properties for http and https proxies can be configured using the following expressions:

systemProp.http.proxyHost= {IP-address of the proxy}
systemProp.http.proxyPort= {port of the proxy}
systemProp.http.nonProxyHost= {excluded IP adresses}

systemProp.https.proxyHost= {IP-address of the proxy}
systemProp.https.proxyPort= {port of the proxy}
systemProp.https.nonProxyHost= {excluded IP adresses}

In both Maven and Gradle configurations, the nonProxyHost property marks IP addresses which should be accessed without communicating through the proxy.