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

Kotlin插件版本不兼容警告:如何设置embedded-kotlin、kotlin-dsl为1.5.21版本

问题背景

构建时弹出Unsupported Kotlin plugin version警告,是因为Gradle默认绑定的embedded-kotlin、kotlin-dsl插件依赖Kotlin 1.4.31版本特性,与项目使用的Kotlin 1.5.21版本不兼容,存在运行表现异常的风险。

解决步骤
  • 第一步:在项目根目录的settings.gradle.kts中添加插件版本全局锁定配置
pluginManagement {
    plugins {
        // 所有使用到的Kotlin相关插件统一指定1.5.21版本
        kotlin("jvm") version "1.5.21"
    }
    resolutionStrategy {
        eachPlugin {
            // 强制所有org.jetbrains.kotlin命名空间下的插件使用1.5.21版本
            if (requested.id.namespace == "org.jetbrains.kotlin") {
                useVersion("1.5.21")
            }
        }
    }
}

如果项目使用Groovy编写构建脚本,对应settings.gradle配置如下:

pluginManagement {
    plugins {
        id 'org.jetbrains.kotlin.jvm' version '1.5.21'
    }
    resolutionStrategy {
        eachPlugin {
            if (requested.id.namespace == 'org.jetbrains.kotlin') {
                useVersion('1.5.21')
            }
        }
    }
}
  • 第二步:在根目录build.gradle.kts中指定kotlin-dsl依赖的Kotlin版本
plugins {
    `kotlin-dsl` apply false
}

subprojects {
    plugins.withType<KotlinDslPlugin> {
        dependencies {
            // 强制kotlin-dsl使用1.5.21版本的Kotlin依赖
            implementation(kotlin("stdlib", "1.5.21"))
            implementation(kotlin("reflect", "1.5.21"))
        }
    }
}
  • 第三步:刷新依赖并重新构建
    执行命令清理旧依赖并构建:
    ./gradlew clean build --refresh-dependencies
验证配置生效

构建完成后执行以下命令检查依赖版本:
./gradlew dependencies | grep "org.jetbrains.kotlin"
确认所有输出的Kotlin相关依赖版本均为1.5.21,无1.4.31版本混合出现即配置成功。

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

相关产品推荐
方舟 Agent Plan

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

最近更新时间:2026.10.04 19:24:00