UnknownHostException错误,构建java grpc示例

时间:2016-10-05 18:40:52

标签: java gradle proxy grpc unknown-host

我正在关注this grpc tutorial,我甚至无法完成第一步。第一步是git克隆项目然后运行

cd examples
./gradlew installDist

我遇到了这个堆栈跟踪

Downloading https://services.gradle.org/distributions/gradle-2.13-bin.zip

Exception in thread "main" java.net.UnknownHostException: services.gradle.org
    at java.net.AbstractPlainSocketImpl.connect(AbstractPlainSocketImpl.java:184)
    at java.net.SocksSocketImpl.connect(SocksSocketImpl.java:392)
    at java.net.Socket.connect(Socket.java:589)
    at sun.security.ssl.SSLSocketImpl.connect(SSLSocketImpl.java:668)
    at sun.security.ssl.BaseSSLSocketImpl.connect(BaseSSLSocketImpl.java:173)
    at sun.net.NetworkClient.doConnect(NetworkClient.java:180)
    at sun.net.www.http.HttpClient.openServer(HttpClient.java:432)
    at sun.net.www.http.HttpClient.openServer(HttpClient.java:527)
    at sun.net.www.protocol.https.HttpsClient.<init>(HttpsClient.java:264)
    at sun.net.www.protocol.https.HttpsClient.New(HttpsClient.java:367)
    at sun.net.www.protocol.https.AbstractDelegateHttpsURLConnection.getNewHttpClient(AbstractDelegateHttpsURLConnection.java:191)
    at sun.net.www.protocol.http.HttpURLConnection.plainConnect0(HttpURLConnection.java:1105)
    at sun.net.www.protocol.http.HttpURLConnection.plainConnect(HttpURLConnection.java:999)
    at sun.net.www.protocol.https.AbstractDelegateHttpsURLConnection.connect(AbstractDelegateHttpsURLConnection.java:177)
    at sun.net.www.protocol.http.HttpURLConnection.getInputStream0(HttpURLConnection.java:1513)
    at sun.net.www.protocol.http.HttpURLConnection.getInputStream(HttpURLConnection.java:1441)
    at sun.net.www.protocol.https.HttpsURLConnectionImpl.getInputStream(HttpsURLConnectionImpl.java:254)
    at org.gradle.wrapper.Download.downloadInternal(Download.java:58)
    at org.gradle.wrapper.Download.download(Download.java:44)
    at org.gradle.wrapper.Install$1.call(Install.java:61)
    at org.gradle.wrapper.Install$1.call(Install.java:48)
    at org.gradle.wrapper.ExclusiveFileAccessManager.access(ExclusiveFileAccessManager.java:65)
    at org.gradle.wrapper.Install.createDist(Install.java:48)
    at org.gradle.wrapper.WrapperExecutor.execute(WrapperExecutor.java:128)
    at org.gradle.wrapper.GradleWrapperMain.main(GradleWrapperMain.java:61)

我认为这是一个代理问题,所以我从this post获得了一些灵感并打开了文件

gradle/wrapper/gradle-wrapper.properties

并添加了行

systemProp.http.proxyHost=<my proxy>
systemProp.http.proxyPort=<my port>

我还用这个

替换了distributionUrl行
distributionUrl=http\://services.gradle.org/distributions/gradle-2.13-bin.zip 

也就是说,我切换了https - &gt; HTTP。

毕竟,我仍然得到相同的堆栈跟踪。

有人有建议吗?

编辑:我添加了

gradle.properties

文件在主目录中,并添加了字段

systemProp.http.proxyHost
systemProd.http.proxyPort

systemProp.https.proxyHost
systemProp.https.proxyPort

但我仍然遇到和以前一样的错误。但是,构建脚本似乎在这一行停滞

Downloading https://services.gradle.org/distributions/gradle-2.13-bin.zip

大约10秒钟左右,失败前。那么......进步?

2 个答案:

答案 0 :(得分:3)

我遇到了同样的问题,两个小时后终于找到了解决方案...

转到项目中的文件 gradlew.bat 并更改 DEFAULT_JVM_OPTS 变量,如下所示:

set DEFAULT_JVM_OPTS=-Dhttp.proxyHost=YOUR_HOST -Dhttp.proxyPort=PORT -Dhttp.proxyUser=USERNAME -Dhttp.proxyPassword=PASSWORD -Dhttps.proxyHost=YOUR_HOST -Dhttps.proxyPort=PORT -Dhttps.proxyUser=USERNAME -Dhttps.proxyPassword=PASSWORD

然后运行gradlew clean build

答案 1 :(得分:0)

我不知道这是否是最佳解决方案,但最终对我有用的是取代

distributionUrl=https\://services.gradle.org/distributions/gradle-2.13-bin.zip 

distributionUrl=https\://services.gradle.org/distributions/gradle-3.0-bin.zip

基本上升级我正在抓取的gradle版本。

我还添加了一个全局

~/.gradle/gradle.properties

在我的主目录中,包含我之前声明的所有代理信息。我这样做后的尝试是不成功的,但我无法肯定地说这样做是否会产生影响。