gradle构建访问被拒绝

时间:2019-02-12 13:38:22

标签: java gradle intellij-idea

嗨,我是gradle和Java和IJ想法的新手。我正在尝试使用gradle构建一些Java项目。当我运行命令时:

C:\Users\xxx\IdeaProjects\example2>gradle build

构建失败。

   FAILURE: Build failed with an exception.

* What went wrong:
Execution failed for task ':compileTestJava'.
> Could not resolve all files for configuration ':testCompileClasspath'.
   > Could not resolve org.testng:testng:6.14.3.
     Required by:
         project :
      > Could not resolve org.testng:testng:6.14.3.
         > Could not get resource 'https://repo.maven.apache.org/maven2/org/testng/testng/6.14.3/testng-6.14.3.pom'.
            > Could not GET 'https://repo.maven.apache.org/maven2/org/testng/testng/6.14.3/testng-6.14.3.pom'.
               > Received fatal alert: access_denied

文件夹IdeaProjects / example2对所有用户完全可用。当我使用--stacktrace选项运行命令时,最后的“原因”是:

            ... 106 more
Caused by: javax.net.ssl.SSLHandshakeException: Received fatal alert: access_denied
        at org.apache.http.conn.ssl.SSLConnectionSocketFactory.createLayeredSocket(SSLConnectionSocketFactory.java:396)

SSL证书可能有问题吗?我正在使用代理连接到网络。

这是我正在使用的build.gradle文件

plugins {
    id 'java'
    id 'idea'
}

group 'jetbrains'
version '1.0'

sourceCompatibility = 1.8

repositories {
    mavenCentral()
}

dependencies {
    //testCompile group: 'junit', name: 'junit', version: '4.12'
    testCompile group: 'org.testng', name: 'testng', version: '6.14.3'
    // https://mvnrepository.com/artifact/io.rest-assured/rest-assured
    //compile group: 'io.rest-assured', name: 'rest-assured', version: '3.1.0'
    //testCompile group: 'io.rest-assured', name: 'rest-assured', version: '3.1.0'
}

1 个答案:

答案 0 :(得分:1)

由于stackoverflow.com/a/22666646/2987755,问题已解决。必须在gradle.properties文件中设置以下变量/属性。

systemProp.http.proxyHost=$proxy
systemProp.http.proxyPort=8080
systemProp.https.proxyHost=$proxy
systemProp.https.proxyPort=8080