Java Gradle 构建失败 [无法解析配置 ':compile' 的所有依赖项。]
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/25243342/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
Gradle build is failing [Could not resolve all dependencies for configuration ':compile'.]
提问by Prajyod Kumar
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**
回答by Aaron Digulla
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. You need to make sure Gradle can access http://repo1.maven.org
.
您可能位于防火墙后面,或者您的 Internet 连接无法正常工作。您需要确保 Gradle 可以访问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).
注意:Maven Central ( http://repo1.maven.org) 可以通过浏览器访问。如果您看到消息“浏览此目录已被禁用”,则表示您的浏览器可以连接到服务器(该错误是我的 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 失败,那么您需要检查浏览器/操作系统的代理设置并相应地配置您的工具。
Related:
有关的:
回答by deveth0
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.
您似乎没有可用的 Internet 连接或尚未配置代理/防火墙。请检查您是否可以从命令行或浏览器访问 repo1.maven.org。
回答by Bharatesh
@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. Stack Overflow Could not resolve all dependencies for configuration ':classpath'
我遇到了GSON 依赖问题,(希望它也能解决其他依赖问题),这个答案解决了这个问题。堆栈溢出无法解析配置':classpath'的所有依赖项
@Kangars post : This is what i have in my gradle.buildfor build script and allprojects
@Kangars 帖子:这是我在gradle.build 中用于构建脚本和所有项目的内容
buildscript {
repositories {
jcenter {
url "http://jcenter.bintray.com/"
}
}
}
allprojects {
repositories {
jcenter {
url "http://jcenter.bintray.com/"
}
}
}
回答by user292049
I used the steps below to fix it.
我使用以下步骤来修复它。
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
Then build your Gradle application and all the connection refused errors no longer appear.
gradle clean build distZip
转到命令提示符并设置 java opts。
SET JAVA_OPTS=-Dhttp.proxyHost=your_proxy_server_name -Dhttp.proxyPort=your_proxy_port -Dhttp.nonProxyHosts=127.0.0.1
然后构建您的 Gradle 应用程序,所有连接被拒绝的错误不再出现。
gradle clean build distZip
回答by phoenix
Using --refresh-dependencies switch with gradle, helped me to resolve this issue.
将 --refresh-dependencies 开关与 gradle 一起使用,帮助我解决了这个问题。
回答by george
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.
这是因为 Internet 连接缓慢或您没有正确配置代理设置。Gradle 需要下载一些依赖项,如果它无法访问存储库,则会触发此错误。您所要做的就是检查您的互联网连接并确保 gradle 可以访问 maven 存储库。
回答by Farrukh Najmi
In my case the problem was resolved when I changed my gradle version from 4.6 to 4.7.
就我而言,当我将 gradle 版本从 4.6 更改为 4.7 时,问题得到了解决。
回答by noob
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:
以下是您可能想要尝试的原因和相应解决方案的列表:
- Internet connectivity issues - Have a good internet speed and connectivity
- Firewall (system or third party) - Ensure firewall is not blocking access to the repository
- Working behind a proxy - Gradle proxy configuration
- Firewall or some random application meddling with proxy application1- Kill the process meddling with the proxy application
- The proxy application causes certificate problems2- Import proxy application's certificate
- 互联网连接问题 - 拥有良好的互联网速度和连接
- 防火墙(系统或第三方) - 确保防火墙不会阻止对存储库的访问
- 在代理后面工作 - Gradle 代理配置
- 防火墙或一些随机应用程序干预代理应用程序1- 终止干预代理应用程序的进程
- 代理申请导致证书问题2- 导入代理申请的证书
References:
参考: