Configure proxy in Gradle | Gradle properties | Using Command Line

To configure a proxy in Gradle, you can make use of the Gradle properties file or provide command-line arguments. Here are two common approaches to configuring a proxy in Gradle:

Gradle Properties File:

Step 1: Locate the gradle.properties file in your Gradle project or create one if it doesn’t exist.

Step 2: Open the gradle.properties file and add the following lines:

systemProp.http.proxyHost=proxy.example.com
systemProp.http.proxyPort=8080
systemProp.https.proxyHost=proxy.example.com
systemProp.https.proxyPort=8080

Note: Replace proxy.example.com and 8080 with the appropriate values for your proxy host and port.

Step 3: Save the gradle.properties file.

Gradle will automatically pick up these properties and use them as proxy configurations when executing tasks.

Command-line Arguments

Step 1: Open your terminal or command prompt.

Step 2: Run your Gradle command with the following additional arguments:

gradle <task> -Dhttp.proxyHost=proxy.example.com -Dhttp.proxyPort=8080 -Dhttps.proxyHost=proxy.example.com -Dhttps.proxyPort=8080

Note: Replace <task> with the specific Gradle task, you want to execute. Adjust the proxy host and port values (proxy.example.com and 8080) according to your proxy configuration.

Step 3: Execute the command, and Gradle will use the provided proxy settings for the given task.

By following either of these methods, you can configure a proxy in Gradle. Whether you choose to use the gradle.properties file or command-line arguments depends on your preference and the level of configuration flexibility you require for different environments.

In case you are using the maven tool then you can follow the steps to configure the proxy below article:

Configure proxy in Maven

Leave a Comment