Gradle Proxy


Gradle proxy configuration - Stack Overflow

Gradle proxy configuration – Stack Overflow

I need web access from Gradle through a proxy server to use the Gradle/Artifactory integration for Jenkins. To reduce possible causes for issues, I manually add the Artifactory plugin in and run it from command line:
apply {
apply from: “}
Following this description I specified the following in in my home directory:
With the above proxy configuration (that is otherwise known to work), it fails:
11:33:17. 699 [ERROR] [] Caused by: Server returned HTTP response code: 407 for URL:
I have two proxy servers to choose from, and one always responds with 407 (Proxy authentication required), the other with 502 (Bad gateway), so obviously, the proxyHost and proxyPort options are used.
As the user name (based on an Active Directory user) contains a backslash, I tried both \ and , but neither worked. The user specified is different from the user that is logged in to the machine and Active Directory. This user’s credentials aren’t valid for the proxy, so I need to be able to specify a different user.
Setting the same options in Jenkins’ or Artifactory’s GUI worked.
asked May 13 ’11 at 11:27
Daniel BeckDaniel Beck5, 7833 gold badges32 silver badges42 bronze badges
Refinement over Daniel’s response:
HTTP Only Proxy configuration
gradlew oxyHost=127. 0. 1 oxyPort=3128 “nProxyHosts=*. |localhost”
HTTPS Only Proxy configuration
gradlew oxyHost=127. 1 oxyPort=3129 “nProxyHosts=*. |localhost”
Both HTTP and HTTPS Proxy configuration
gradlew oxyHost=127. 1 oxyPort=3128 oxyHost=127. |localhost”
Proxy configuration with user and password
gradlew oxyHost=127. 1 oxyPort=3128 – oxyHost=127. 1 oxyPort=3129 oxyUser=user oxyPassword=pass oxyUser=user oxyPassword=pass |
worked for me (with operties in either homedir or project dir, build was still failing). Thanks for pointing the issue at gradle that gave this workaround. See reference doc at Update
You can also put these properties into operties (see:).
madlymad5, 9656 gold badges33 silver badges62 bronze badges
answered Mar 26 ’14 at 16:01
Guillaume BercheGuillaume Berche2, 6932 gold badges11 silver badges15 bronze badges
This is my operties, please note those HTTPS portion
answered May 6 ’16 at 18:54
Kampau OcuKampau Ocu8816 silver badges4 bronze badges
In my I have the following task, which uses the usual linux proxy settings, HTTP_PROXY and HTTPS_PROXY, from the shell env:
task setHttpProxyFromEnv {
def map = [‘HTTP_PROXY’: ”, ‘HTTPS_PROXY’: ”]
for (e in ()) {
def key = ()
if (key in map) {
def base = map[key]
def url = ()
println ” – systemProp. ${base}${}:${}”
tProperty(“${base}. proxyHost”, ())
tProperty(“${base}. proxyPort”, ())}}}
pendsOn setHttpProxyFromEnv
answered Nov 10 ’15 at 18:06
For me, works adding this configuration in the operties file of the project, where the file is:
proxyUrl is the url of the proxy server (….. )
proxyPort is the port (usually 8080)
USER is my domain user
PASSWORD, my password
In this case, the proxy for and is the same
answered Sep 8 ’16 at 13:57
rtrujillorrtrujillor1, 0941 gold badge11 silver badges23 bronze badges
Check out at
c:Usersyour username\operties:

answered Sep 3 ’18 at 14:17
Try the following:
gradle oxyHost=yourProxy oxyPort=yourPort oxyUser=usernameProxy oxyPassword=yourPassoword
Shaun2, 41518 silver badges33 bronze badges
answered Dec 15 ’14 at 18:49
Using a very simple “Request a URL” Java program, I was able to replicate the issue.
oxyUser and oxyPassword seem to be non-standard, albeit popular, options, as they’re not described in the Java reference page linked from the Gradle tutorial; even though the Gradle manual mentions them.
It seems Java programs that wish to support proxy authentication need to do this manually (and I was able to do this using the code on the linked page).
I submitted this issue (and a fix) to the Gradle issue tracker. Raised issue GRADLE-1556 was resolved in 1. 0-milestone-8 (Feb 2012)
Paul Verest53. 3k42 gold badges178 silver badges301 bronze badges
answered May 13 ’11 at 13:57
Create a file called operties inside the project folder where the file is present. Add the following entry
If you are using DNS for proxy then add it like
For IP just specify the IP with out or
Check gradle official doc for more details and setting up proxy at global level
answered Nov 8 ’17 at 11:19
user2720864user27208647, 7744 gold badges43 silver badges59 bronze badges
There are 2 ways for using Gradle behind a proxy:
Add arguments in command line
(From Guillaume Berche’s post)
Add these arguments in your gradle command:
oxyHost=your_proxy__host oxyPort=your_proxy__port
or these arguments if you are using:
Add lines in gradle configuration file
in operties
add the following lines:
(for operties file location, please refer to official documentation
EDIT: as said by @Joost:
A small but important detail that I initially overlooked: notice that the actual host name does NOT contain protocol part of the URL…
answered Feb 2 ’18 at 12:00
ThibaultThibault5815 silver badges6 bronze badges
Based on SourceSimian’s response; this worked on Windows domain user accounts. Note that the Username does not have domain included,
tProperty(“${base}. proxyPort”, ())
tProperty(“${base}. proxyUser”, “Username”)
tProperty(“${base}. proxyPassword”, “Password”)}}}
answered Dec 28 ’17 at 19:03
Kunal B. 5236 silver badges21 bronze badges
In case my I try to set up proxy from android studio Appearance & Behaviour => System Settings => HTTP Proxy. But the proxy did not worked out so I click no proxy.
Checking NO PROXY will not remove the proxy setting from the
operties(Global). You need to manually remove it.
So I remove all the properties starting with systemProp for example – *, localhost
answered May 15 ’18 at 13:03
AnirbanAnirban4, 1695 gold badges48 silver badges76 bronze badges
An update to @sourcesimian ‘s and @kunal-b’s answer which dynamically sets the username and password if configured in the system properties.
The following sets the username and password if provided or just adds the host and port if no username and password is set.
//Get proxyHost, port, username, and password from system properties
// in the format username:[email protected]:proxyport
def (val1, val2) = ( ‘@’)
def (val3, val4) = kenize( ‘//’)
def(userName, password) = kenize(‘:’)
//println ” – systemProp. proxyUser”, String())
tProperty(“${base}. proxyPassword”, String())}}}
answered Mar 26 ’18 at 18:14
NorbertNorbert4694 silver badges12 bronze badges
If this issue with HTTP error 407 happened to selected packages only then the problem is not in the proxy setting and internet connection. You even may expose your PC to the internet through NAT and still will face this problem. Typically at the same time you can download desired packages in browser.
The only solution I find: delete the folder in your profile (not in the project). After that sync the project, it will take a long time but restore everything.
answered Nov 3 ’17 at 12:51
AlmazAlmaz7609 silver badges12 bronze badges
If you are using flutter, add the following line in android/operties
*, localhost
Dharman23. 8k20 gold badges60 silver badges111 bronze badges
answered May 23 at 18:47
saurabhsaurabh4534 silver badges7 bronze badges
Edit your ~/ file, then add the following:
=127. 1 -DsocksProxyPort=1080 -DProxyHost=127. 1 -DProxyPort=1081 -DProxyHost=127. 1 -DProxyPort=1081
DsocksProxyHost is the socks5 proxy host
DProxyHost is the proxy host
It worked for me.
answered Aug 3 at 3:09
Cosmo DaiCosmo Dai1671 silver badge5 bronze badges
In the kotlin setting files the properties should be defined like this:
extra[“”]=”127. 1″
answered Aug 20 at 6:04, 5613 gold badges33 silver badges37 bronze badges
I met the same issue after I installed an older version of SDK and set JAVA_HOME in, none of the solutions above help me but finally RESTARTED COMPUTER(Mac) then the error gone.
answered Aug 23 at 16:09
ahgoodahgood1, 52918 silver badges17 bronze badges
If you are behind proxy and using eclipse, go to Window Menu –> Preferences –> General –> Network Connections. Select the Active Providers as ‘Manual’.
Under Proxy entries section, click on HTTPS, click Edit and add proxy host & port. If username and password are required, give that as well. It worked for me!
answered Aug 13 ’15 at 9:57
whoamiwhoami1, 3691 gold badge20 silver badges23 bronze badges
Not the answer you’re looking for? Browse other questions tagged java proxy active-directory windows-server-2008 gradle or ask your own question.
Build Environment - Gradle User Manual

Build Environment – Gradle User Manual

Interested in configuring your Build Cache to speed up builds? Register here for our Build Cache training session to learn some of the tips and tricks top engineering teams are using to increase build speed.
Gradle provides multiple mechanisms for configuring behavior of Gradle itself and specific projects. The following is a reference for using these mechanisms.
When configuring Gradle behavior you can use these methods, listed in order of highest to lowest precedence (first one wins):
Command-line flags such as –build-cache. These have precedence over properties and environment variables.
System properties such as stored in a operties file.
Gradle properties such as that are typically stored in a operties file in a project root directory or GRADLE_USER_HOME environment variable.
Environment variables such as GRADLE_OPTS sourced by the environment that executes Gradle.
Aside from configuring the build environment, you can configure a given project build using Project properties such as -PreleaseType=final.
Gradle properties
Gradle provides several options that make it easy to configure the Java process that will be used to execute your build. While it’s possible to configure these in your local environment via GRADLE_OPTS or JAVA_OPTS, it is useful to be able to store certain settings like JVM memory configuration and Java home location in version control so that an entire team can work with a consistent environment. To do so, place these settings into a operties file committed to your version control system.
The final configuration taken into account by Gradle is a combination of all Gradle properties set on the command line and your operties files. If an option is configured in multiple locations, the first one found in any of these locations wins:
command line, as set using the -P / –project-prop environment options.
operties in GRADLE_USER_HOME directory.
operties in project root directory.
operties in Gradle installation directory.
Note that the location of the Gradle user home may have been changed beforehand via the system property passed on the command line.
The following properties can be used to configure the Gradle build environment:
(true, false)
When set to true, Gradle will reuse task outputs from any previous build, when possible, resulting is much faster builds. Learn more about using the build cache.
When set to true, individual input property hashes and the build cache key for each task are logged on the console. Learn more about task output caching.
Enables incubating configuration on demand, where Gradle will attempt to configure only necessary projects.
(auto, plain, rich, verbose)
Customize console output coloring or verbosity. Default depends on how Gradle is invoked. See command-line logging for additional details.
When set to true the Gradle Daemon is used to run the build. Default is true.
(# of idle millis)
Gradle Daemon will terminate itself after specified number of idle milliseconds. Default is 10800000 (3 hours).
When set to true, Gradle will run the build with remote debugging enabled, listening on port 5005. Note that this is the equivalent of adding -agentlib:jdwp=transport=dt_socket, server=y, suspend=y, address=5005 to the JVM command line and will suspend the virtual machine until a debugger is attached. Default is false.
(path to JDK home)
Specifies the Java home for the Gradle build process. The value can be set to either a jdk or jre location, however, depending on what your build does, using a JDK is safer. A reasonable default is derived from your environment (JAVA_HOME or the path to java) if the setting is unspecified. This does not affect the version of Java used to launch the Gradle client VM (see Environment variables).
(JVM arguments)
Specifies the JVM arguments used for the Gradle Daemon. The setting is particularly useful for configuring JVM memory settings for build performance. This does not affect the JVM settings for the Gradle client VM.
(quiet, warn, lifecycle, info, debug)
When set to quiet, warn, lifecycle, info, or debug, Gradle will use this log level. The values are not case sensitive. The lifecycle level is the default. See Choosing a log level.
When configured, Gradle will fork up to JVMs to execute projects in parallel. To learn more about parallel task execution, see the section on Gradle build performance.
(low, normal)
Specifies the scheduling priority for the Gradle daemon and all processes launched by it. Default is normal. See also performance command-line options.
Configures verbose logging when watching the file system.
Default is off.
Toggles watching the file system.
When enabled Gradle re-uses information it collects about the file system between builds.
Enabled by default on operating systems where Gradle supports this feature.
(all, fail, summary, none)
When set to all, summary or none, Gradle will use different warning type display. See Command-line logging options for details.
(max # of worker processes)
When configured, Gradle will use a maximum of the given number of workers. Default is number of CPU processors. See also performance command-line options.
The following example demonstrates usage of various properties.
Example 1. Setting properties with a operties file
gister(‘printProps’) {
doLast {
println commandLineProjectProp
println gradlePropertiesProp
println systemProjectProp
println operties[‘system’]}}
// Project properties can be accessed via delegation
val commandLineProjectProp: String by project
val gradlePropertiesProp: String by project
val systemProjectProp: String by project
gister(“printProps”) {
$ gradle -q -PcommandLineProjectProp=commandLineProjectPropValue printProps
System properties
Using the -D command-line option, you can pass a system property to the JVM which runs Gradle. The -D option of the gradle command has the same effect as the -D option of the java command.
You can also set system properties in operties files with the prefix systemProp.
Specifying system properties in operties
The following system properties are available. Note that command-line options take precedence over system properties.
gradle. wrapperUser=(myuser)
Specify user name to download Gradle distributions from servers using HTTP Basic Authentication. Learn more in Authenticated wrapper downloads.
gradle. wrapperPassword=(mypassword)
Specify password for downloading a Gradle distribution using the Gradle wrapper.
(path to directory)
Specify the Gradle user home directory.
Specify the supported TLS versions in a comma separated format. For example: TLSv1. 2, TLSv1. 3.
In a multi project build, “systemProp. ” properties set in any project except the root will be ignored. That is, only the root project’s operties file will be checked for properties that begin with the “systemProp. ” prefix.
Environment variables
The following environment variables are available for the gradle command. Note that command-line options and system properties take precedence over environment variables.
Specifies JVM arguments to use when starting the Gradle client VM. The client VM only handles command line input/output, so it is rare that one would need to change its VM options.
The actual build is run by the Gradle daemon, which is not affected by this environment variable.
Specifies the Gradle user home directory (which defaults to $USER_HOME/ if not set).
Specifies the JDK installation directory to use for the client VM. This VM is also used for the daemon, unless a different one is specified in a Gradle properties file with
Project properties
You can add properties directly to your Project object via the -P command line option.
Gradle can also set project properties when it sees specially-named system properties or environment variables. If the environment variable name looks like ORG_GRADLE_PROJECT_prop=somevalue, then Gradle will set a prop property on your project object, with the value of somevalue. Gradle also supports this for system properties, but with a different naming pattern, which looks like Both of the following will set the foo property on your Project object to “bar”.
Setting a project property via a system property
Setting a project property via an environment variable
The properties file in the user’s home directory has precedence over property files in the project directories.
This feature is very useful when you don’t have admin rights to a continuous integration server and you need to set property values that should not be easily visible. Since you cannot use the -P option in that scenario, nor change the system-level configuration files, the correct strategy is to change the configuration of your continuous integration build job, adding an environment variable setting that matches an expected pattern. This won’t be visible to normal users on the system.
You can access a project property in your build script simply by using its name as you would use a variable.
If a project property is referenced but does not exist, an exception will be thrown and the build will fail.
Configuring JVM memory
You can adjust JVM options for Gradle in the following ways:
The Gradle property controls the VM running the build. It defaults to -Xmx512m “-XX:MaxMetaspaceSize=256m”
Changing JVM settings for the build VM
-XX:MaxMetaspaceSize=512m -XX:+HeapDumpOnOutOfMemoryError -Dfile. encoding=UTF-8
The JAVA_OPTS environment variable controls the command line client, which is only used to display console output. It defaults to -Xmx64m
Changing JVM settings for the client VM
JAVA_OPTS=”-Xmx64m -XX:MaxPermSize=64m -XX:+HeapDumpOnOutOfMemoryError -Dfile. encoding=UTF-8″
There is one case where the client VM can also serve as the build VM:
If you deactivate the Gradle Daemon and the client VM has the same settings as required for the build VM, the client VM will run the build directly.
Otherwise the client VM will fork a new VM to run the actual build in order to honor the different settings.
Certain tasks, like the test task, also fork additional JVM processes. You can configure these through the tasks themselves.
They all use -Xmx512m by default.
Example 2. Set Java compile options for JavaCompile tasks
plugins {
id ‘java’}
tasks. withType(JavaCompile) {
mpilerArgs += [‘-Xdoclint:none’, ‘-Xlint:none’, ‘-nowarn’]}
tasks. withType(). configureEach {
mpilerArgs = listOf(“-Xdoclint:none”, “-Xlint:none”, “-nowarn”)}
Build scans will tell you information about the JVM that executed the build when you use the –scan option.
Configuring a task using project properties
It’s possible to change the behavior of a task based on project properties specified at invocation time.
Suppose you’d like to ensure release builds are only triggered by CI. A simple way to handle this is through an isCI project property.
Example 3. Prevent releasing outside of CI
gister(‘performRelease’) {
if (project. hasProperty(“isCI”)) {
println(“Performing release actions”)} else {
throw new InvalidUserDataException(“Cannot perform release outside of CI”)}}}
gister(“performRelease”) {
throw InvalidUserDataException(“Cannot perform release outside of CI”)}}}
$ gradle performRelease -PisCI=true –quiet
Performing release actions
Accessing the web through a HTTP proxy
Configuring an HTTP or HTTPS proxy (for downloading dependencies, for example) is done via standard JVM system properties. These properties can be set directly in the build script; for example, setting the HTTP proxy host would be done with tProperty(‘oxyHost’, ”). Alternatively, the properties can be specified in operties.
Configuring an HTTP proxy using operties
*. |localhost
There are separate settings for HTTPS.
Configuring an HTTPS proxy using operties
You may need to set other properties to access other networks. Here are 2 references that may be helpful:
in the Ant codebase
JDK 7 Networking Properties
NTLM Authentication
If your proxy requires NTLM authentication, you may need to provide the authentication domain as well as the username and password. There are 2 ways that you can provide the domain for authenticating to a NTLM proxy:
Set the oxyUser system property to a value like domain/username.
Provide the authentication domain via the system property.
Error:Unknown host You may need ...

Error:Unknown host You may need …

i have tried it many times but its giving me same to set the proxy so that this error is solved
Zoe24. 2k16 gold badges103 silver badges143 bronze badges
asked Nov 12 ’15 at 5:08
Go to..
File > Settings > Appearance & Behavior > System Settings > HTTP Proxy Enable following option Auto-detect proxy settings
and press checkConnection button for test
answered Nov 28 ’15 at 12:09
vahid karimivahid karimi9341 gold badge10 silver badges6 bronze badges
In my case issue occurred after following:
I selected proxy settings from Android Studio settings when I was working in a network behind a proxy. When I disconnected from that network and connected to home network which doesn’t have a proxy, I removed the proxy settings from Android Studio, but gradle seemed to take the old proxy settings.
The problem was that gradle had also saved the proxy settings in following file when I set proxy settings in Android Studio, but it hasn’t got removed when I removed proxy settings from Android Studio. %HOME%\operties
When I removed the proxy settings from this file, gradle sync worked again.
answered Mar 25 ’19 at 14:46
Lahiru ChandimaLahiru Chandima17. 8k15 gold badges80 silver badges141 bronze badges
Update your project level to latest version – it works for me
classpath ”
answered Jan 4 ’19 at 9:01
Ranjith KumarRanjith Kumar13. 9k9 gold badges99 silver badges127 bronze badges
I had the same problem. What worked for me was:
Go to File>Invalidate caches/restart>Invalidate and restart.
Hope it works for you too.
If that doesn’t work, give your system access to internet and click on Help>Check for Updates. And update android studio to latest versions. All gradle along with plugins will be updated and i guess it should resolve the issue.
answered May 1 ’19 at 9:28
Android Plugin for Gradle HTTP proxy settings
For application-specific HTTP proxy settings, set the proxy settings in the file as required for each application module.
apply plugin: ‘lication’
android {…
defaultConfig {… }… }
For project-wide HTTP proxy settings, set the proxy settings in the gradle/operties file.
# Project-wide Gradle settings…….
Please read Official Document Configuration
answered Nov 12 ’15 at 5:45
IntelliJ AmiyaIntelliJ Amiya71. 4k14 gold badges158 silver badges188 bronze badges
make sure that you disable the proxy setting.
settting > apperance and behaviour > Http Proxy > and select no proxy check box and check the connection after you select no proxy or auto detect proxy setting > the apply ok
answered Apr 24 ’17 at 7:37
Check your internet connection is stable or not. May be this will work with you
answered Apr 30 ’19 at 16:40
Download a recent gradle release from
Unzip the file and copy the gradle folder e. g. gradle 4. 0 into C — program files — android — android studio — gradle.
On your android studio goto file — settings — Build, Execution, Deployment –Build Tools — Gradle and choose Use local gradle distribution, in the gradle home locate your gradle folder and click apply. Then click okay.
This solved the problem for me. Your android studio might require a more recent gradle release, make sure you download a gradle that is compatible with your studio or latest releases.
answered Sep 12 ’17 at 8:48
OpeyemiOpeyemi5335 silver badges8 bronze badges
Go To: File –> Setting –> Build, Execution, Deployment –> Gradle, then tick the use local Gradle distribution, then set Gradle home by giving path to Gradle. Tick offline work.
Like so:
Omar Einea2, 4106 gold badges21 silver badges34 bronze badges
answered Mar 24 ’18 at 11:34
If you are using an proxy server, revise the following proxy settings in “operties” file in your project’s root folder. If not using proxy server, just delete those entries.
answered May 19 ’18 at 11:29
MuratMurat1353 bronze badges
Preferences –> Build, Execution, Deployment –> Gradle –> Android studio
answered Apr 4 ’19 at 16:01
The problem is you are not able to download gradle from the host specified in
In my case this happened after I refactored the code using Idea.
To get this working:
1. Be sure you can download the zip file at URL in the file mentioned above
2. If you can you may wanna check your proxy configuration or env vars
answered Jun 7 ’19 at 20:46
GNUtonGNUton7566 silver badges7 bronze badges
For some reason, using a shared machine, I couldn`t figure out where this proxy properties is comming from.
So a workaround to fix this is add in you project operties the following (empty properties). So It will override top hierarchy configuration:
answered Feb 4 ’20 at 21:24
I Solved the problem like this. In Android Studio go to File menu and select the Invalidate Caches/Restart…
I hope it will work for you.
answered Apr 7 ’20 at 11:57
If you are using WAMP/XAMP server turn it off.
This resolved my problem.
answered May 23 ’20 at 13:49
Alright, I also had this error and it persist for serveral hours trying the solutions provided on stackoverflow but couldn’t resolve the problem. I realised that I had a network proxy configuration connected to an ethernet and i was currently connnected over network tethering on my phone. I disabled the auto detect proxy settings from my network setting on windows and deleting the IP Address and Port number for manual proxy setup and it worked!
answered Jun 24 at 1:15
for me changing ext. kotlin_version in the worked.
replace this
ext. kotlin_version = “1. 5. 20″
with this
ext. 0”
answered Jun 28 at 9:50
MerajMeraj1316 bronze badges
Not the answer you’re looking for? Browse other questions tagged android gradle android-gradle-plugin or ask your own question.

Frequently Asked Questions about gradle proxy

How do I add a proxy to Gradle?

Configuring Proxy Settings in GradleCreate a . gradle directory in your home directory.Open/Create the file gradle. properties in this directory.Add the following settings: systemProp. http. proxyHost=proxy systemProp. http. proxyPort=8080 systemProp. http. nonProxyHosts=*. sap. corp|localhost systemProp. https.

How do I change my proxy settings in Gradle?

Go To: File –> Setting –> Build, Execution, Deployment –> Gradle, then tick the use local Gradle distribution, then set Gradle home by giving path to Gradle. Tick offline work. If you are using an http proxy server, revise the following proxy settings in “gradle. properties” file in your project’s root folder.Mar 25, 2019

How do I get rid of proxy Gradle?

Remove proxy from all of the following places.File > Settings > System settings > HTTP Proxy.Project (As mentioned in the previous answer by @seorefbe)Mar 29, 2018

About the author


If you 're a SEO / IM geek like us then you'll love our updates and our website. Follow us for the latest news in the world of web automation tools & proxy servers!

By proxyreview

Recent Posts

Useful Tools