问题
I am following this grpc tutorial and I haven't even been able to make it through the first step. The first step is to git clone the project and then run
cd examples
./gradlew installDist
I am hit with this stack trace
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)
I thought that was a proxy issue, so I took some inspiration from this post and opened up the file
gradle/wrapper/gradle-wrapper.properties
and added the lines
systemProp.http.proxyHost=<my proxy>
systemProp.http.proxyPort=<my port>
I also replaced distributionUrl line with this
distributionUrl=http\://services.gradle.org/distributions/gradle-2.13-bin.zip
That is, I switched https --> http.
After all of this, I am still getting the same stack trace.
Anybody have advice?
EDIT : I added a
gradle.properties
file in the home directory, and added the fields
systemProp.http.proxyHost
systemProd.http.proxyPort
and
systemProp.https.proxyHost
systemProp.https.proxyPort
but I still got the same error as before. HOWEVER, the build script appeared to stall on this line
Downloading https://services.gradle.org/distributions/gradle-2.13-bin.zip
For about 10 seconds or so, before failing. So... progress?
回答1:
I had the same problem and finally found this solution after 2 hours...
Go to the file gradlew.bat in your project and change DEFAULT_JVM_OPTS variable as below:
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
then run gradlew clean build
.
回答2:
I don't know if it is an optimal solution, but what eventually worked for me was to replace
distributionUrl=https\://services.gradle.org/distributions/gradle-2.13-bin.zip
with
distributionUrl=https\://services.gradle.org/distributions/gradle-3.0-bin.zip
Essentially upgrading the version of gradle I am grabbing.
I also added a global
~/.gradle/gradle.properties
In my home directory with all the proxy info I had previously declared. My attempt to build after doing this was unsuccessful, but I can't say for sure if doing this had zero impact.
来源:https://stackoverflow.com/questions/39881448/unknownhostexception-error-building-java-grpc-example