简体   繁体   English

Gradle 构建失败 [无法解析配置 ':compile' 的所有依赖项。]

[英]Gradle build is failing [Could not resolve all dependencies for configuration ':compile'.]

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当我通过将 jettyRun 作为命令运行 bundle.gradle在此处输入图像描述

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

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. Gradle需要下载错误消息中列出的依赖项才能编译项目。

You're probably behind a firewall or your Internet connection isn't working. 您可能在防火墙后面,或者您的Internet连接无法正常工作。 You need to make sure Gradle can access http://repo1.maven.org . 您需要确保Gradle可以访问http://repo1.maven.org

Note: Maven Central ( http://repo1.maven.org ) can be accessed with a browser. 注意:可以使用浏览器访问Maven Central( http://repo1.maven.org )。 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). 如果看到消息“已禁用该目录的浏览”,则表明您的浏览器可以连接到服务器(错误是Maven Central的特殊消息,不是标准的HTTP错误消息)。

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. 如果看到此消息,但Maven或Gradle失败,则需要检查浏览器/ OS的代理设置并相应地配置工具。

Related: 有关:

将--refresh-dependencies开关与gradle一起使用,可以帮助我解决此问题。

@Aaron Digulla said I have firewall problem. @Aaron Digulla说我有防火墙问题。

I was having problem with GSON dependency , (hope it will solve other dependecy problems also) and this answer solved the problem. 我在使用GSON依赖项时遇到问题(希望它也可以解决其他依赖问题),并且此答案解决了问题。 Stack Overflow Could not resolve all dependencies for configuration ':classpath' 堆栈溢出无法解析配置':classpath'的所有依赖项

@Kangars post : This is what i have in my gradle.build for build script and allprojects @Kangars post:这是我在gradle.build中拥有的构建脚本和allprojects

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

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

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. Gradle需要下载一些依赖项,如果它无法访问存储库,则会引发此错误。 All you have to do is check your internet connection and make sure gradle can access the maven repository. 您所要做的就是检查您的Internet连接,并确保gradle可以访问maven存储库。

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. 请检查是否可以从命令行或浏览器访问repo1.maven.org。

I used the steps below to fix it. 我使用以下步骤对其进行了修复。

  1. Go to command prompt and set the java opts. 转到命令提示符并设置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应用程序,所有连接被拒绝的错误将不再出现。

    gradle clean build distZip

就我而言,当我将gradle版本从4.6更改为4.7时,问题得以解决。

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. Connection to http://repo1.maven.org refused的根本原因指示,由于gradle无法从存储库中获取某些依赖项,因此构建失败。

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 在代理后面工作-Gradle代理配置
  4. Firewall or some random application meddling with proxy application 1 - Kill the process meddling with the proxy application 防火墙或一些随机的应用与代理应用1插手-杀死进程与代理申请插手
  5. The proxy application causes certificate problems 2 - Import proxy application's certificate 代理应用程序导致证书问题2-导入代理应用程序的证书

References: 参考文献:

  1. Telerik forum's answer on how to fix internet connectivity issue while using Fiddler Telerik论坛有关使用Fiddler时如何解决Internet连接问题的答案
  2. Telerik forum's answer on secure connection issue while using Fiddler 使用Fiddler时Telerik论坛对安全连接问题的解答

For my case it was a poor connection issue so the IDE couldn't get resources online就我而言,这是一个连接不良的问题,因此 IDE 无法在线获取资源

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 Gradle 构建开始失败并出现错误 - 无法解析配置“:编译”的所有文件 - Gradle build started failing with error - Could not resolve all files for configuration ':compile' Gradle Drools 6.2无法解析配置':compile'的所有依赖项 - Gradle Drools 6.2 Could not resolve all dependencies for configuration ':compile' Gradle:无法解析配置“:classpath”的所有依赖项 - Gradle: Could not resolve all dependencies for configuration ':classpath' 无法解析配置“:classpath”的所有工件。 > 无法解析 com.android.tools.build:gradle:4.1.0 - Could not resolve all artifacts for configuration ':classpath'. > Could not resolve com.android.tools.build:gradle:4.1.0 在 Gradle 中使用 SWT 无法解决所有依赖项 - Using SWT in Gradle could not resolve all dependencies 无法解析配置':app:_debugApkCopy'的所有依赖项 - Could not resolve all dependencies for configuration ':app:_debugApkCopy' 无法解析配置':app:debugCompileClasspath的所有依赖项 - Could not resolve all dependencies for configuration ':app:debugCompileClasspath 无法解析配置的所有依赖项:类路径' - Could not resolve all dependencies for configuration :classpath' 在Jersey / JAX-RS项目中,Gradle“无法解析配置的所有依赖项” - Gradle 'Could not resolve all dependencies for configuration' in Jersey/JAX-RS project 具有依赖关系的Gradle多项目设置->无法解决所有依赖关系 - Gradle Multi-Project Setup with Dependencies -> Could not resolve all dependencies
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM