java Gradle 无法下载公司代理背后的发行版
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/34640698/
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 failing to download distribution behind company proxy
提问by Jon Erickson
Trying to get Jenkins behind my corp proxy to build my java library project and it keeps timing out during download of the distribution. I've followed many guides on trying to get gradle to utilize proxy settings in the gradle.properties
file build it doesn't seem to work. I know the proxyHost and proxyPort is correct. Is there something that I'm overlooking or is it a different issue other than the proxy?
试图让 Jenkins 支持我的公司代理来构建我的 Java 库项目,并且在下载分发版期间它一直超时。我已经遵循了许多指南,试图让 gradle 在gradle.properties
文件构建中使用代理设置,但它似乎不起作用。我知道 proxyHost 和 proxyPort 是正确的。有什么我忽略的东西还是代理以外的其他问题?
build.gradle
构建.gradle
apply plugin: 'java'
apply plugin: 'maven'
apply plugin: 'maven-publish'
apply plugin: 'idea'
sourceCompatibility = 1.8
def baseVersion = "1.0"
def jenkinsBuildNumber = System.getenv('BUILD_NUMBER')
version = jenkinsBuildNumber != null ? baseVersion + "." + jenkinsBuildNumber : baseVersion
println 'Version: ' + version
group = 'com.company.MyLibrary'
repositories {
mavenCentral()
}
apply plugin: 'groovy'
jar {
from "LICENSE.md"
}
dependencies {
compile "com.google.guava:guava:19.0"
compile "junit:junit:4.12"
compile "org.assertj:assertj-core:3.2.0"
compile "org.mockito:mockito-core:2.0.31-beta"
compile "org.powermock:powermock-module-junit4:1.6.2"
compile "org.powermock:powermock-api-mockito:1.6.2"
testCompile "com.google.guava:guava:19.0"
testCompile "junit:junit:4.12"
testCompile "org.assertj:assertj-core:3.2.0"
testCompile "org.mockito:mockito-core:2.0.31-beta"
testCompile "org.powermock:powermock-module-junit4:1.6.2"
testCompile "org.powermock:powermock-api-mockito:1.6.2"
}
task sourcesJar(type: Jar) {
dependsOn classes
classifier 'sources'
from sourceSets.main.allSource
}
task javadocJar(type: Jar, dependsOn: javadoc) {
classifier = 'javadoc'
from javadoc.destinationDir
}
artifacts {
archives sourcesJar
archives javadocJar
}
task wrapper(type: Wrapper) {
gradleVersion = '2.10'
distributionUrl = "http://services.gradle.org/distributions/gradle-${gradleVersion}-all.zip"
}
gradle.properties
gradle.properties
systemProp.https.proxyHost=proxy.company.net
systemProp.https.proxyPort=8989
systemProp.http.proxyHost=proxy.company.net
systemProp.http.proxyPort=8989
systemProp.https.nonProxyHosts=*.company.com|localhost
org.gradle.daemon=true
Jenkins console output
詹金斯控制台输出
20:45:09 Started by an SCM change
20:45:09 [EnvInject] - Loading node environment variables.
20:45:09 Building on master in workspace /var/lib/jenkins/workspace/MyLibrary
20:45:09 [WS-CLEANUP] Deleting project workspace...
20:45:09 [WS-CLEANUP] Done
20:45:09 Cloning the remote Git repository
20:45:09 Cloning repository ssh://[email protected]/~jon/MyLibrary.git
20:45:09 > git init /var/lib/jenkins/workspace/MyLibrary # timeout=10
20:45:09 Fetching upstream changes from ssh://[email protected]/~jon/MyLibrary.git
20:45:09 > git --version # timeout=10
20:45:09 > git -c core.askpass=true fetch --tags --progress ssh://[email protected]/~jon/MyLibrary.git +refs/heads/*:refs/remotes/origin/*
20:45:10 > git config remote.origin.url ssh://[email protected]/~jon/MyLibrary.git # timeout=10
20:45:10 > git config --add remote.origin.fetch +refs/heads/*:refs/remotes/origin/* # timeout=10
20:45:10 > git config remote.origin.url ssh://[email protected]/~jon/MyLibrary.git # timeout=10
20:45:10 Fetching upstream changes from ssh://[email protected]/~jon/MyLibrary.git
20:45:10 > git -c core.askpass=true fetch --tags --progress ssh://[email protected]/~jon/MyLibrary.git +refs/heads/*:refs/remotes/origin/*
20:45:11 Seen branch in repository origin/master
20:45:11 Seen 1 remote branch
20:45:11 Checking out Revision 2ece1927e5fb1d368aba28a107f6fe2c2accb9fa (origin/master)
20:45:11 > git config core.sparsecheckout # timeout=10
20:45:11 > git checkout -f 2ece1927e5fb1d368aba28a107f6fe2c2accb9fa
20:45:11 > git rev-list 66fe56731f935be83c91e38ced426aea7bba0b8f # timeout=10
20:45:11 [EnvInject] - Injecting environment variables from a build step.
20:45:11 [Gradle] - Launching build.
20:45:11 [MyLibrary] $ /var/lib/jenkins/workspace/MyLibrary/gradlew -Dcommit=master clean test
20:45:11 Downloading http://services.gradle.org/distributions/gradle-2.10-all.zip
20:47:18
20:47:18 Exception in thread "main" java.net.ConnectException: Connection timed out
20:47:18 at java.net.PlainSocketImpl.socketConnect(Native Method)
20:47:18 at java.net.AbstractPlainSocketImpl.doConnect(AbstractPlainSocketImpl.java:350)
20:47:18 at java.net.AbstractPlainSocketImpl.connectToAddress(AbstractPlainSocketImpl.java:206)
20:47:18 at java.net.AbstractPlainSocketImpl.connect(AbstractPlainSocketImpl.java:188)
20:47:18 at java.net.SocksSocketImpl.connect(SocksSocketImpl.java:392)
20:47:18 at java.net.Socket.connect(Socket.java:589)
20:47:18 at java.net.Socket.connect(Socket.java:538)
20:47:18 at sun.net.NetworkClient.doConnect(NetworkClient.java:180)
20:47:18 at sun.net.www.http.HttpClient.openServer(HttpClient.java:432)
20:47:18 at sun.net.www.http.HttpClient.openServer(HttpClient.java:527)
20:47:18 at sun.net.www.http.HttpClient.<init>(HttpClient.java:211)
20:47:18 at sun.net.www.http.HttpClient.New(HttpClient.java:308)
20:47:18 at sun.net.www.protocol.http.HttpURLConnection.getNewHttpClient(HttpURLConnection.java:1175)
20:47:18 at sun.net.www.protocol.http.HttpURLConnection.plainConnect0(HttpURLConnection.java:1123)
20:47:18 at sun.net.www.protocol.http.HttpURLConnection.plainConnect(HttpURLConnection.java:998)
20:47:18 at sun.net.www.protocol.http.HttpURLConnection.connect(HttpURLConnection.java:932)
20:47:18 at sun.net.www.protocol.http.HttpURLConnection.getInputStream0(HttpURLConnection.java:1512)
20:47:18 at sun.net.www.protocol.http.HttpURLConnection.getInputStream(HttpURLConnection.java:1440)
20:47:18 at org.gradle.wrapper.Download.downloadInternal(Download.java:58)
20:47:18 at org.gradle.wrapper.Download.download(Download.java:44)
20:47:18 at org.gradle.wrapper.Install.call(Install.java:61)
20:47:18 at org.gradle.wrapper.Install.call(Install.java:48)
20:47:18 at org.gradle.wrapper.ExclusiveFileAccessManager.access(ExclusiveFileAccessManager.java:65)
20:47:18 at org.gradle.wrapper.Install.createDist(Install.java:48)
20:47:18 at org.gradle.wrapper.WrapperExecutor.execute(WrapperExecutor.java:128)
20:47:18 at org.gradle.wrapper.GradleWrapperMain.main(GradleWrapperMain.java:61)
20:47:18 Build step 'Invoke Gradle script' changed build result to FAILURE
20:47:18 Build step 'Invoke Gradle script' marked build as failure
20:47:18 Finished: FAILURE
回答by Jon Erickson
My solution was to update my global ~/.gradle/gradle.properties
file with the correct proxy settings:
我的解决方案是~/.gradle/gradle.properties
使用正确的代理设置更新我的全局文件:
org.gradle.daemon=true
systemProp.https.proxyHost=proxy.company.net
systemProp.https.proxyPort=8181
systemProp.http.proxyHost=proxy.company.net
systemProp.http.proxyPort=8181
systemProp.https.nonProxyHosts=*.company.com|localhost
this is in effect, the same as passing these as command line args to gradlew
(./gradlew -Dhttp.proxyHost=xxx -Dhttp.proxyPort=xxx -Dhttps.proxyHost=xxx -Dhttps.proxyPort=xxx
这实际上与将这些作为命令行参数传递给gradlew
(./gradlew -Dhttp.proxyHost=xxx -Dhttp.proxyPort=xxx -Dhttps.proxyHost=xxx -Dhttps.proxyPort=xxx
回答by Alex M
For me it worked by using the following lines to the gradle.properties application folder
对我来说,它通过使用以下几行到 gradle.properties应用程序文件夹来工作
systemProp.https.proxyHost=proxy.company.net
systemProp.https.proxyPort=8080
systemProp.https.proxyPassword=
systemProp.http.proxyHost=proxy.company.net
systemProp.http.proxyPort=8080
systemProp.http.proxyPassword=
systemProp.https.nonProxyHosts=*.company.com|localhost
Do not forgot to enter also your password for the proxy. Hope this helps
不要忘记输入您的代理密码。希望这可以帮助