I don't have a proxy, but Gradle says "Connect to 127.0.0.1:8888 [/127.0.0.1] failed", even after removing ~/.gradle

Viewed 3957

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

4 Answers

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.*'

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?

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.

Even though I have never used a proxy, for some unfathomable reason HTTP and HTTPS proxy had got enabled in the Mac System Properties:

enter image description here

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

enter image description here

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

Related