17

I am trying for so many days to resolve this exception , followed many blogs and couldn't find solution. when I run a bundle.gradle by giving jettyRun as command enter image description here

I am getting an exception 



    **FAILURE: Build failed with an exception.

        * What went wrong:
        Could not resolve all dependencies for configuration ':compile'.
        > Could not resolve javax.servlet:servlet-api:2.5.
          Required by:
              :1-SimpleServlet:unspecified
           > Could not GET 'http://repo1.maven.org/maven2/javax/servlet/servlet-api/2.5/servlet-api-2.5.pom'.
              > Connection to http://repo1.maven.org refused
        > Could not resolve org.apache.commons:commons-io:1.3.2.
          Required by:
              :1-SimpleServlet:unspecified
           > Could not GET 'http://repo1.maven.org/maven2/org/apache/commons/commons-io/1.3.2/commons-io-1.3.2.pom'.
              > Connection to http://repo1.maven.org refused**
Prajyod Kumar
  • 395
  • 2
  • 4
  • 15

10 Answers10

18

The real error is this:

Connection to http://repo1.maven.org refused

Gradle needs to download the dependencies listed in the error message to be able to compile the project.

You're probably behind a firewall or your Internet connection isn't working. You need to make sure Gradle can access http://repo1.maven.org.

Note: Maven Central (http://repo1.maven.org) can be accessed with a browser. If you see the message "Browsing for this directory has been disabled" that means your browser could connect to the server (the error is a special message my Maven Central, not a standard HTTP error message).

If you see this but Maven or Gradle fail, then you need to check your browser's/OS's proxy settings and configure your tool accordingly.

Related:

Aaron Digulla
  • 321,842
  • 108
  • 597
  • 820
  • the dependencies are listed in my project , but when I open http://repo1.maven.org there was a message "Browsing for this directory has been disabled."..so how can I fix this then? – Prajyod Kumar Aug 11 '14 at 12:39
  • @PrajyodKumar: Read the rest of the text. – Aaron Digulla Aug 11 '14 at 13:23
  • To fix the problem with Gradle, you need to configure it to use the same proxy settings as your web browser. – Aaron Digulla Aug 11 '14 at 13:25
  • I have same problem. I can access google.com normally but can not access repo1.maven.org. Not meaning can not access. The message is "Browsing for this directory has been disabled...." – Bulma Jul 24 '15 at 07:15
  • @KouTokyo: Maven Central doesn't allow to access this URL with a browser. But when you get the error page, that means your browser could connect to Maven Central - so the firewall is OK. – Aaron Digulla Jul 24 '15 at 11:06
8

Using --refresh-dependencies switch with gradle, helped me to resolve this issue.

phoenix
  • 607
  • 6
  • 13
2

In my case the problem was resolved when I changed my gradle version from 4.6 to 4.7.

Farrukh Najmi
  • 5,055
  • 3
  • 35
  • 54
1

@Aaron Digulla said I have firewall problem.

I was having problem with GSON dependency, (hope it will solve other dependecy problems also) and this answer solved the problem. Stack Overflow Could not resolve all dependencies for configuration ':classpath'

@Kangars post : This is what i have in my gradle.build for build script and allprojects

buildscript {
repositories {
    jcenter {
        url "http://jcenter.bintray.com/"
    }
  }
}

allprojects {
repositories {
    jcenter {
        url "http://jcenter.bintray.com/"
    }
  }
}
Community
  • 1
  • 1
Bharatesh
  • 8,943
  • 3
  • 38
  • 67
1

This is because of slow internet connection or you haven't configure proxy settings correctly. Gradle needs to download some dependencies , if it cant access the repository it fires this error. All you have to do is check your internet connection and make sure gradle can access the maven repository.

george
  • 41
  • 6
1

The root cause Connection to http://repo1.maven.org refused indicates that the build is failing as gradle is not able to fetch some dependencies from the repository.

Here is a list of causes and corresponding resolutions you might want to try:

  1. Internet connectivity issues - Have a good internet speed and connectivity
  2. Firewall (system or third party) - Ensure firewall is not blocking access to the repository
  3. Working behind a proxy - Gradle proxy configuration
  4. Firewall or some random application meddling with proxy application1 - Kill the process meddling with the proxy application
  5. The proxy application causes certificate problems2 - Import proxy application's certificate

References:

  1. Telerik forum's answer on how to fix internet connectivity issue while using Fiddler
  2. Telerik forum's answer on secure connection issue while using Fiddler
noob
  • 774
  • 1
  • 10
  • 23
0

It looks like you don't have a working internet connection or haven't configured your proxy/firewall. Please check if you can access repo1.maven.org from commandline or a browser.

deveth0
  • 488
  • 1
  • 5
  • 15
0

I used the steps below to fix it.

  1. Go to command prompt and set the java opts.

    SET JAVA_OPTS=-Dhttp.proxyHost=your_proxy_server_name -Dhttp.proxyPort=your_proxy_port -Dhttp.nonProxyHosts=127.0.0.1
    
  2. Then build your Gradle application and all the connection refused errors no longer appear.

    gradle clean build distZip

BSMP
  • 4,596
  • 8
  • 33
  • 44
user292049
  • 1,138
  • 1
  • 14
  • 20
0

Mine worked after turning on the VPN. Although the build seems to take a long time and seems to stall at 85%, the service is actually building and I'm able to load it

Vy Nguyen
  • 11
  • 1
-1

For my case it was a poor connection issue so the IDE couldn't get resources online

Fred
  • 332
  • 4
  • 5