升级到Gradle 4.10时,尝试编译时遇到以下错误:
Execution failed for task ':buildSrc:compileKotlin'.
> Could not resolve all files for configuration ':buildSrc:kotlinCompilerPluginClasspath'.
> Could not find org.jetbrains.kotlin:kotlin-scripting-compiler-embeddable:1.2.60.
Searched in the following locations: file:/Users/<user-name>/.gradle/caches/4.10/embedded-kotlin-repo-1.2.60-2/repo/org/jetbrains/kotlin/kotlin-scripting-compiler-embeddable/1.2.60/kotlin-scripting-compiler-embeddable-1.2.60.jar
Required by:
project :buildSrc
> Could not find org.jetbrains.kotlin:kotlin-sam-with-receiver:1.2.60.
Required by:
project :buildSrc
请注意,我在Gradle编译过程中使用了buildSrc
。
答案 0 :(得分:10)
这是由于Kotlin DSL 1.0中的重大更改造成的:
kotlin-dsl插件现在需要声明存储库
在Kotlin 1.2.60中,驱动Kotlin编译器的Kotlin Gradle插件需要额外的依赖项,而Gradle Kotlin DSL脚本本身并不需要这些依赖项,并且这些依赖项并没有嵌入到Gradle中。
可以通过在应用kotlin-dsl插件的项目上添加包含Kotlin编译器依赖项的存储库来解决此问题:
repositories { jcenter() }
答案 1 :(得分:0)
build.gradle.kts应该包含
plugins {
`kotlin-dsl`
}
// Required since Gradle 4.10+.
repositories {
jcenter()
}