首页 > 解决方案 > gradle 构建访问被拒绝

问题描述

嗨,我是 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'
}

标签: javagradleintellij-idea

解决方案


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

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

推荐阅读