You need to enable JavaScript to run this app.
优惠活动
大模型
产品
解决方案
定价
更多

新安装的Gradle执行run命令失败,依赖解析出错求助

Gradle执行gradle run失败问题求助

执行gradle run时,:compileJava任务失败,具体报错如下:

**.local ~/Hello  **
╰─➤  gradle run
╰─➤  gradle run   
> Task :compileJava FAILED

FAILURE: Build failed with an exception.

* What went wrong:
Execution failed for task ':compileJava'.
> Could not resolve all files for configuration ':compileClasspath'.
   > Could not resolve com.google.guava:guava:29.0-jre.
     Required by:
         project :
      > Could not resolve com.google.guava:guava:29.0-jre.
         > Could not get resource 'https://repo.maven.apache.org/maven2/com/google/guava/guava/29.0-jre/guava-29.0-jre.pom'.
            > Could not GET 'https://repo.maven.apache.org/maven2/com/google/guava/guava/29.0-jre/guava-29.0-jre.pom'.
               > The server may not support the client's requested TLS protocol versions: (TLSv1.2, TLSv1.3). You may need to configure the client to allow other protocols to be used. See: https://docs.gradle.org/8.0.2/userguide/build_environment.html#gradle_system_properties
                  > PKIX path building failed: sun.security.provider.certpath.SunCertPathBuilderException: unable to find valid certification path to requested target

* Try:
> Run with --stacktrace option to get the stack trace.
> Run with --info or --debug option to get more log output.
> Run with --scan to get full insights.

* Get more help at https://help.gradle.org

BUILD FAILED in 405ms
1 actionable task: 1 executed

环境信息

Java版本

java -version                                                                                          1 ↵
openjdk version "1.8.0_362"
OpenJDK Runtime Environment Corretto-8.362.08.1 (build 1.8.0_362-b08)
OpenJDK 64-Bit Server VM Corretto-8.362.08.1 (build 25.362-b08, mixed mode)

Gradle版本

Gradle 8.0.2
Build time:   2023-03-03 16:41:37 UTC
Revision:     7d6581558e226a580d91d399f7dfb9e3095c2b1d
Kotlin:       1.8.10
Groovy:       3.0.13
Ant:          Apache Ant(TM) version 1.10.11 compiled on July 10 2021
JVM:          1.8.0_362 (Amazon.com Inc. 25.362-b08)
OS:           Mac OS X 13.2.1 aarch64

build.gradle配置

/*
 * This file was generated by the Gradle 'init' task.
 *
 * This generated file contains a sample Java project to get you started.
 * For more details take a look at the Java Quickstart chapter in the Gradle
 * User Manual available at https://docs.gradle.org/6.5/userguide/tutorial_java_projects.html
 */

plugins {
    // Apply the java plugin to add support for Java
    id 'java'

    // Apply the application plugin to add support for building a CLI application.
    id 'application'
}

repositories {
    // Use jcenter for resolving dependencies.
    // You can declare any Maven/Ivy/file repository here.
    mavenCentral()
}

dependencies {
    // This dependency is used by the application.
    implementation 'com.google.guava:guava:29.0-jre'

    // Use JUnit Jupiter API for testing.
    testImplementation 'org.junit.jupiter:junit-jupiter:5.7.2'
}

application {
    // Define the main class for the application
    mainClass = 'hello.App'
}

test {
    // Use junit platform for unit tests
    useJUnitPlatform()
}

解决方案

1. 修复PKIX证书信任问题

这是核心报错原因,Java无法验证Maven Central的SSL证书,处理步骤:

  • 导出Maven Central的根证书:访问对应网站,通过浏览器地址栏的锁图标查看证书,导出为.crt格式文件。
  • 将证书导入Java信任库:
    打开终端执行命令(替换证书路径):
    sudo keytool -import -trustcacerts -file /path/to/your/certificate.crt -keystore $JAVA_HOME/jre/lib/security/cacerts
    
    默认信任库密码为changeit,输入密码后确认导入即可。

2. 配置Gradle TLS协议(可选)

若证书导入后仍有TLS相关报错,可指定兼容协议:

  • 在项目根目录创建gradle.properties文件,添加:
    systemProp.jdk.tls.client.protocols=TLSv1.2,TLSv1.3
    systemProp.https.protocols=TLSv1.2,TLSv1.3
    
    或临时通过命令指定:
    gradle run -Djdk.tls.client.protocols=TLSv1.2,TLSv1.3 -Dhttps.protocols=TLSv1.2,TLSv1.3
    

3. 检查网络代理配置(若有)

如果处于代理环境,需在gradle.properties中添加代理信息:

systemProp.http.proxyHost=你的代理地址
systemProp.http.proxyPort=你的代理端口
systemProp.https.proxyHost=你的代理地址
systemProp.https.proxyPort=你的代理端口

若代理需要认证,补充:

systemProp.http.proxyUser=你的代理用户名
systemProp.http.proxyPassword=你的代理密码
systemProp.https.proxyUser=你的代理用户名
systemProp.https.proxyPassword=你的代理密码

内容的提问来源于stack exchange,提问作者Sebastian Williams

相关产品推荐
方舟 Agent Plan

超全模态模型 × Harness 升级,最新支持 Deepseek-V4.1-Flash、GLM-5.3 系列、Doubao-Seedream-5.0-pro、Kimi-K3 (部分), 限时 9.9 元起

最近更新时间:2026.07.26 06:15:22