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

Gradle构建报错:找不到org.gradle:gradle-tooling-api:7.6的原因与解决

Gradle构建时无法解析gradle-tooling-api:7.6的问题

错误日志

执行gradle test时收到以下错误:

FAILURE: Build failed with an exception.

* What went wrong:
A problem occurred configuring root project 'testgl'.
> Could not resolve all artifacts for configuration 'classpath'.   
> Could not find org.gradle:gradle-tooling-api:7.6.
     Searched in the following locations:
       - https://repo.maven.apache.org/maven2/org/gradle/gradle-tooling-api/7.6/gradle-tooling-api-7.6.pom
       - https://plugins.gradle.org/m2/org/gradle/gradle-tooling-api/7.6/gradle-tooling-api-7.6.pom
     Required by:
         root project :

* 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.

Deprecated Gradle features were used in this build, making it incompatible with Gradle 9.0.

You can use '--warning-mode all' to show the individual deprecation warnings and determine if they come from your own scripts or plugins.

For more on this, please refer to https://docs.gradle.org/8.11.1/userguide/command_line_interface.html#sec:command_line_warnings in the Gradle documentation.

BUILD FAILED in 3s
Configuration cache entry stored.

项目build.gradle配置

buildscript {
    repositories {
        mavenCentral()
    }
    dependencies {
        classpath 'org.gradle:gradle-tooling-api:7.6'
    }
}

plugins {
    id 'java'
    id 'application'
}

repositories {
    mavenCentral()
}

dependencies {
    implementation 'com.google.guava:guava:32.1.2-jre'
    implementation 'org.apache.commons:commons-lang3:3.13.0'
    implementation 'org.slf4j:slf4j-api:2.0.9'
    implementation 'com.googlecode.plist:dd-plist:1.26'
    implementation files('libs/xxx.jar')
    implementation gradleApi() 
    implementation localGroovy() 
}

java {
    toolchain {
        languageVersion = JavaLanguageVersion.of(21)
    }
}

application {
    mainClass = 'testgl.test1'
}

tasks.named('test') {
    useJUnitPlatform()
}

sourceSets {
    main {
        java {
            srcDirs = ['C:/vscode/test1/app/src/main/java']
        }
    }
}

jar {
    manifest {
        attributes(
            'Main-Class': 'testgl.test1'
        )
    }
}

已尝试的操作

  • 确认Maven Central仓库中存在gradle-tooling-api:7.6,但构建时仍无法解析;
  • 清理项目后重新构建,错误依旧;
  • 使用--stacktrace参数执行构建,未获得有效信息;
  • 确认使用的Gradle版本兼容,但问题仍存在。

疑问

  1. 找不到gradle-tooling-api:7.6的原因是什么?
  2. 如何解决该问题?是否需要更换该依赖的版本?
  3. 能否安全移除该依赖,还是Gradle的某些功能必须依赖它?
  4. 哪里有针对该问题的官方文档或参考资源?

问题解答

1. 找不到gradle-tooling-api:7.6的原因

  • Gradle Tooling API的部分版本可能未完全同步到Maven Central,或你的网络环境无法正常访问仓库,导致拉取失败;
  • 你在buildscript中声明该依赖完全无必要:Tooling API是供外部程序(如IDE、自定义构建工具)调用Gradle时使用的,普通Java项目的构建脚本不需要引入它;
  • 项目中已依赖的gradleApi()是Gradle核心API,用于编写自定义任务或插件,和Tooling API是完全不同的组件,两者没有依赖关系。

2. 解决方法及版本建议

  • 优先推荐:直接移除buildscript中的该依赖,因为你的项目场景根本不需要它,移除后即可解决错误;
  • 如果确实需要使用Tooling API(比如开发Gradle集成工具),请:
    • 确保buildscript的仓库配置包含Gradle官方仓库;
    • 使用与当前项目使用的Gradle版本一致的Tooling API版本(比如你用的是Gradle 8.11.1,就对应使用8.11.1版本的Tooling API);
  • 检查网络环境,确保能正常访问Maven Central或Gradle插件仓库,必要时配置代理。

3. 能否安全移除该依赖

完全可以安全移除。你的项目是普通Java应用,仅使用java和application插件,构建过程不需要Tooling API。移除该依赖不会影响任何现有功能,反而能解决当前的构建错误。

4. 官方文档参考

Gradle官方文档中关于Tooling API的章节会明确它的用途、适用场景和正确的依赖配置方式;另外,构建脚本依赖配置的相关文档也会说明哪些依赖是项目构建必需的。你可以在Gradle官方文档中搜索“Tooling API”获取详细内容。


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

相关产品推荐
方舟 Agent Plan

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

最近更新时间:2026.06.15 17:43:15