【问题标题】:Cannot access built-in declaration Ensure that you have a dependency on the Kotlin standard library无法访问内置声明确保您对 Kotlin 标准库有依赖
【发布时间】:2019-08-22 08:00:39
【问题描述】:

错误:(11, 40) Kotlin: 无法访问内置声明 'kotlin.coroutines.SuspendFunction1'。确保您有一个 对 Kotlin 标准库的依赖

fun Route.coroutineHandler(fn: suspend (RoutingContext) -> Unit) {
    handler { ctx ->
        launch(ctx.vertx().dispatcher()) {
            try {
                fn(ctx)
            } catch (e: Exception) {
                ctx.fail(e)
            }
        }
    }

【问题讨论】:

  • "为了使用协程 [...],您需要添加对 kotlinx-coroutines-core 模块的依赖,如 in the project README 所述。" – @987654322 @.

标签: intellij-idea kotlin


【解决方案1】:

Slaw 评论一样,只需将kotlinx-coroutines-core 依赖项添加到您的项目中,如README 中所述

Maven

添加依赖(也可以添加其他需要的模块):

<dependency>
    <groupId>org.jetbrains.kotlinx</groupId>
    <artifactId>kotlinx-coroutines-core</artifactId>
    <version>1.3.5</version>
</dependency>

并确保您使用最新的 Kotlin 版本:

<properties>
    <kotlin.version>1.3.70</kotlin.version>
</properties>

分级

添加依赖(也可以添加其他需要的模块):

dependencies {
    implementation 'org.jetbrains.kotlinx:kotlinx-coroutines-core:1.3.5'
}

并确保您使用最新的 Kotlin 版本:

buildscript {
    ext.kotlin_version = '1.3.70'
}

确保您在存储库列表中有jcenter()mavenCentral()

repository {
    jcenter()
}

【讨论】:

    猜你喜欢
    • 2021-03-02
    • 1970-01-01
    • 2022-01-15
    • 2019-04-05
    • 2016-06-09
    • 2011-08-06
    • 2019-10-03
    • 2021-04-01
    • 2021-09-28
    相关资源
    最近更新 更多