10

My gradle seems to insist on downloading packages from what looks like a proxy address. With this command I stop all Gradle daemons, remove any Gradle configuration, and build a random project from GitHub that has no proxy settings in its gradle.properties (I tried other projects, same result):

./gradlew  --stop ;\
pkill -f '.*GradleDaemon.*' ;\
rm -rf ~/.gradle ;\
env ;\
./gradlew build

The ./gradlew build part outputs this error:

FAILURE: Build failed with an exception.

* What went wrong:
A problem occurred configuring root project 'commons-app'.
> Could not resolve all artifacts for configuration ':classpath'.
   > Could not resolve com.android.tools.build:gradle:4.0.0.
     Required by:
         project :
      > Could not resolve com.android.tools.build:gradle:4.0.0.
         > Could not get resource 'https://dl.google.com/dl/android/maven2/com/android/tools/build/gradle/4.0.0/gradle-4.0.0.pom'.
            > Could not GET 'https://dl.google.com/dl/android/maven2/com/android/tools/build/gradle/4.0.0/gradle-4.0.0.pom'.
               > Connect to 127.0.0.1:8888 [/127.0.0.1] failed: Connection refused (Connection refused)

For reference, here is the output of the first commands, with a line break between each for clarity:

Stopping Daemon(s)
1 Daemon stopped

TERM_PROGRAM=Apple_Terminal
TERM=xterm-256color
SHELL=/bin/bash
TMPDIR=/var/folders/jh/ffpydh_90rz7fhyq9ycryhnw00plfm/T/
TERM_PROGRAM_VERSION=433
OLDPWD=/Users/nicolasraoul/src
TERM_SESSION_ID=59D12079-D9B2-4C13-8366-219454D7760C
USER=nicolasraoul
SSH_AUTH_SOCK=/private/tmp/com.apple.launchd.OejMgJbaF5/Listeners
PATH=/Users/nicolasraoul/Library/Android/sdk/emulator:/Users/nicolasraoul/Library/Android/sdk/tools:/usr/local/git/current/bin:/usr/local/bin:/usr/bin:/bin:/usr/local/sbin:/usr/sbin:/sbin:/Users/nicolasraoul/Library/Python/2.7/bin
PWD=/Users/nicolasraoul/src/commons-app2
ANDROID_SDK=/Users/nicolasraoul/Library/Android/sdk
LANG=en_US.UTF-8
XPC_FLAGS=0x0
HISTCONTROL=
XPC_SERVICE_NAME=0
HOME=/Users/nicolasraoul
SHLVL=1
LOGNAME=nicolasraoul
_=/usr/bin/env

Downloading https://services.gradle.org/distributions/gradle-6.2.2-all.zip
[...]

What could be the problem?

I have found several similar questions, but none of their answers apply because:

  • I am using pure Gradle, so no Android Studio.
  • ~/.gradle is empty
  • I don't have a proxy and I have not willingly configured one anywhere. By the way gradle-6.2.2-all.zip gets downloaded fine as part of the build, so my Internet is working.

macOS Catalina 10.15.5

Nicolas Raoul
  • 58,567
  • 58
  • 222
  • 373
  • Did you try to find out if a program is using port 8888 as suggested [here](https://stackoverflow.com/a/60387667/2089675)? Once you find out, you can kill it and try again. Would be nice to know what gradle does with port 8888, or maybe something else you ran earlier did not die and is using the port :/ – smac89 Jul 29 '20 at 02:26
  • @smac89: `netstat -vanp tcp | grep 8888` and `sudo lsof -i tcp:8888` both return empty. I believe that means no program is using that port (which is good as I am not willingly running anything on that port). – Nicolas Raoul Jul 29 '20 at 02:33
  • You don't say what OS but check inside `/etc/profile` and see if anything has been set in there. Also do you have `lynx` you can test on the same machine? – user3788685 Aug 01 '20 at 19:41
  • @user3788685: I added the OS, thanks! `/etc/profile` just calls `path_helper` and `/etc/bashrc`, themselves doing nothing very special, in particular nothing network-related. – Nicolas Raoul Aug 02 '20 at 11:02
  • Odd. I don't know much about macos. my only other thoughts are; have you ever installed knowingly anything for some dev testing maybe? Are you on a corporate network or open LAN/Internet? Maybe worth running rootkit hunter or similar if this has happened out of the blue – user3788685 Aug 02 '20 at 12:20
  • from what I know of the gradle source code, the only way to set a proxy is via the java system properties (which are seeded from -D or gradle.properties), I would try and get gradle to dump the full set from System.getProperties() then perhaps track down where it could be getting set.. – stringy05 Aug 04 '20 at 23:32

7 Answers7

30

If you had a proxy configured before but gradle still thinks that it is enabled, be sure to kill all gradle daemons:

pkill -f '.*GradleDaemon.*'
Nicolas Raoul
  • 58,567
  • 58
  • 222
  • 373
Werner Altewischer
  • 10,080
  • 4
  • 53
  • 60
  • 1
    I tried literally ~10 other things and this is what worked for me. Thank you. Something about Charles proxy really f**** with Gradle, even after quitting the proxy, but this fixed it. – Matt.M Jul 02 '21 at 22:29
7

It seems that you have some proxy settings which are redirecting your https traffic to 127.0.0.1:8888

Do you have the HTTPS_PROXY environment variable set?

Do you have https.proxyHost and https.proxyPort properties configured in $USER_HOME/.gradle/gradle.properties?

lance-java
  • 25,497
  • 4
  • 59
  • 101
  • You are right that Gradle somehow seems to believe I have configured a proxy, however: 1) As you can see in my output of `env`, there is no proxy-related variable set 2) As you can see in the question, I remove `~/.gradle` immediately before running Gradle. – Nicolas Raoul Jul 26 '20 at 11:07
  • 1
    thanks a lot... my problem solved after check main gradle.properties file. – S.Grou May 09 '21 at 09:16
4

To investigate I wrote this small Java program that output the system properties seen by Java:

public class Main {
        public static void main(String[] args) {
                System.out.println("Hello");
                System.getProperties().list(System.out);
        }
}

It revealed that Java sees a proxy even though env does not.

HTTP and HTTPS proxy had been enabled in the Mac System Properties somehow (I highly suspect the Charles program did it):

enter image description here

Unchecking them solved the problem, allowing Gradle to build successfully.

enter image description here

Nicolas Raoul
  • 58,567
  • 58
  • 222
  • 373
2

After trying all the above options without sucess, I restarted my computer and now it works. I isn't a really technical solution but on another hand it is.

After more than 1 occurrence, I think it is related with Proxyman software, but just turning it off didn't work

Rui Cardoso
  • 739
  • 6
  • 18
  • Not really. I killed the daemon (no reboot required for that), didn't have any system env or toggle in the network options. If it helps someone, I think it was related with proxyman software. – Rui Cardoso Jan 27 '22 at 18:39
1

did you use charles to capture the http request?try to turn off the macos proxy in charles

  • 3
    Welcome to Stack Overflow! Please phrase this as an explained conditional answer, in order to avoid the impression of asking a clarification question instead of answering (for which a comment should be used instead of an answer, compare https://meta.stackexchange.com/questions/214173/why-do-i-need-50-reputation-to-comment-what-can-i-do-instead ). For example like "If your problem is ... then the solution is to .... because .... ." – Yunnosch Feb 08 '23 at 11:22
  • Yes I had used Charles proxy to capture web requests. Charles probably changed my network settings. – Nicolas Raoul Feb 10 '23 at 01:55
0

If you are a mac user goto below address and check the gradle.properties file for that proxy and comment it

$USER_HOME/.gradle/gradle.properties

> # systemProp.http.proxyHost=127.0.0.1
> # systemProp.http.proxyPort=10809
> # systemProp.https.proxyHost=127.0.0.1
> # systemProp.https.proxyPort=10809

If You are windows user goto

C:\Users\am823.gradle

And comment those lines.

starball
  • 20,030
  • 7
  • 43
  • 238
gtr Developer
  • 2,369
  • 16
  • 12
0

It was due to charles proxy issue in my situation, even though I quited the charles.

pkill -f '.*GradleDaemon.*'

can work.

Jack.Li
  • 11
  • 1