Gradle
proxy configuration
build tool
Java
software development

Gradle proxy settings: configure an HTTP and HTTPS proxy

Codemia Knowledge Hub ·

To make Gradle use a proxy, add systemProp.http.* and systemProp.https.* entries to a gradle.properties file. Put them in the Gradle user home directory to apply them to every build, or in a project's root directory to apply them to that project only. Without this, Gradle cannot fetch dependencies and plugins from remote repositories on networks where all traffic must pass through a proxy server.

Setting the proxy for all projects

Edit gradle.properties in the Gradle user home directory: &#126;/.gradle/gradle.properties on Unix-like systems or C:\Users\<user>\.gradle\gradle.properties on Windows.

properties
1# HTTP proxy settings
2systemProp.http.proxyHost=<proxyHost>
3systemProp.http.proxyPort=<proxyPort>
4# Optional, if authentication is needed
5systemProp.http.proxyUser=<proxyUser>
6systemProp.http.proxyPassword=<proxyPassword>
7systemProp.http.nonProxyHosts=localhost|127.0.0.1|*.mycompany.com
8
9# HTTPS proxy settings
10systemProp.https.proxyHost=<proxyHost>
11systemProp.https.proxyPort=<proxyPort>
12# Optional, if authentication is needed
13systemProp.https.proxyUser=<proxyUser>
14systemProp.https.proxyPassword=<proxyPassword>
15systemProp.https.nonProxyHosts=localhost|127.0.0.1|*.mycompany.com

The user and password lines are optional. nonProxyHosts lists the hosts Gradle should reach directly, separated by |. Keep comments on their own lines: in a .properties file, a # after a value becomes part of the value.

Setting the proxy for one project

Put the same entries in the gradle.properties file in that project's root directory.

Example with authentication

For a proxy with these details:

  • Proxy host: proxy.example.com
  • Proxy port: 8080
  • Proxy user: user123
  • Proxy password: pass123
  • Non-proxy hosts: localhost, 127.0.0.1 and *.example.org

the configuration is:

properties
1systemProp.http.proxyHost=proxy.example.com
2systemProp.http.proxyPort=8080
3systemProp.http.proxyUser=user123
4systemProp.http.proxyPassword=pass123
5systemProp.http.nonProxyHosts=localhost|127.0.0.1|*.example.org
6
7systemProp.https.proxyHost=proxy.example.com
8systemProp.https.proxyPort=8080
9systemProp.https.proxyUser=user123
10systemProp.https.proxyPassword=pass123
11systemProp.https.nonProxyHosts=localhost|127.0.0.1|*.example.org

The user and password entries are only needed when the proxy requires authentication. Keep these credentials out of files that are shared or committed to version control; prefer the per-user ~/.gradle/gradle.properties, GRADLE_OPTS, or another secure store.

Proxy settings reference

Configuration itemDescriptionExample value
Proxy hostHostname or IP address of the proxy serverproxy.example.com
Proxy portPort number of the proxy server8080
Proxy userOptional; username for proxy authenticationuser123
Proxy passwordOptional; password for proxy authenticationpass123
Non-proxy hostsHosts that should bypass the proxylocalhost | 127.0.0.1 | \*.example.org
Proxy environment variablesAlternative way to pass the settingsGRADLE_OPTS with -D flags

Testing and troubleshooting the proxy

  • Environment variables: Gradle does not read HTTP_PROXY or HTTPS_PROXY. For settings that change between machines, put them in the per-user ~/.gradle/gradle.properties, or pass the same JVM properties through the GRADLE_OPTS environment variable, for example GRADLE_OPTS="-Dhttps.proxyHost=proxy.example.com -Dhttps.proxyPort=8080".
  • Check connectivity: run a simple task such as dependencies to confirm Gradle can reach the repositories through the proxy.
  • Debug failures: run with --debug to get detailed logs of connection problems.
  • Protect credentials: never commit proxy passwords to a repository or leave them in publicly accessible files.

Course
Beginner
27 lessons
10 hours
System Design Fundamentals

Build a strong foundation in designing scalable, reliable distributed systems.

View the course
System Design practice on Codemia

Work through 120+ system design problems with detailed solutions, from rate limiters to multi-region storage.

Practice system design