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

按JetBrains教程创建Kotlin应用时Gradle同步失败求助

问题

按照JetBrains官方教程创建基于Gradle Groovy的Kotlin应用时,构建失败。相关截图如下:
截图1
截图2

完整构建日志:

Starting Gradle Daemon...
Gradle Daemon started in 1 s 83 ms

FAILURE: Build failed with an exception.

* What went wrong:
A problem occurred configuring root project 'hello'.
> Could not resolve all files for configuration ':classpath'.
   > Could not resolve org.jetbrains.kotlin:kotlin-gradle-plugin-api:1.7.21.
     Required by:
         project : > org.jetbrains.kotlin.jvm:org.jetbrains.kotlin.jvm.gradle.plugin:1.7.21 > org.jetbrains.kotlin:kotlin-gradle-plugin:1.7.21
      > Could not resolve org.jetbrains.kotlin:kotlin-gradle-plugin-api:1.7.21.
         > Could not get resource 'https://plugins.gradle.org/m2/org/jetbrains/kotlin/kotlin-gradle-plugin-api/1.7.21/kotlin-gradle-plugin-api-1.7.21.pom'.
            > Could not GET 'https://jcenter.bintray.com/org/jetbrains/kotlin/kotlin-gradle-plugin-api/1.7.21/kotlin-gradle-plugin-api-1.7.21.pom'. Received status code 403 from server: Forbidden
   // 省略重复的同类错误日志
* 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 7s

问题原因

核心问题是JCenter仓库已停止服务。日志显示Gradle尝试从https://jcenter.bintray.com拉取Kotlin Gradle插件依赖时返回403 Forbidden,JCenter早在2021年就宣布停止新包上传,后续逐步关闭了公开访问,现在已无法正常获取依赖资源。

解决步骤

  1. 替换仓库配置
    打开项目根目录下的build.gradle文件,将所有jcenter()仓库引用替换为mavenCentral(),示例如下:
buildscript {
    repositories {
        gradlePluginPortal()
        // 移除 jcenter()
        mavenCentral() // 添加Maven中央仓库
    }
    dependencies {
        classpath "org.jetbrains.kotlin:kotlin-gradle-plugin:1.7.21"
    }
}

allprojects {
    repositories {
        gradlePluginPortal()
        // 移除 jcenter()
        mavenCentral() // 添加Maven中央仓库
    }
}
  1. 升级Kotlin版本(可选但推荐)
    旧版本Kotlin Gradle插件可能默认依赖JCenter,建议升级到较新的稳定版(如1.9.x),新版本已适配Maven Central,同时能获得更多功能和Bug修复。修改build.gradle中的插件版本:
classpath "org.jetbrains.kotlin:kotlin-gradle-plugin:1.9.20"
  1. 清理缓存并重新构建
    执行以下命令清理Gradle缓存并强制刷新依赖:
  • Linux/macOS:
./gradlew clean build --refresh-dependencies
  • Windows:
gradlew.bat clean build --refresh-dependencies

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

相关产品推荐
方舟 Agent Plan

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

最近更新时间:2026.08.03 20:55:28