我正在尝试使用IntelliJ IDEA Community 2020使用协程运行本地Kotlin项目。
这是我的build.gradle的样子:
plugins {
id 'org.jetbrains.kotlin.multiplatform' version '1.3.72'
}
repositories {
mavenCentral()
}
kotlin {
// For ARM, should be changed to iosArm32 or iosArm64
// For Linux, should be changed to e.g. linuxX64
// For MacOS, should be changed to e.g. macosX64
// For Windows, should be changed to e.g. mingwX64
mingwX64("mingw") {
binaries {
executable {
// Change to specify fully qualified name of your application's entry point:
entryPoint = 'sample.main'
// Specify command-line arguments, if necessary:
runTask?.args('')
}
}
}
sourceSets {
// Note: To enable common source sets please comment out 'kotlin.import.noCommonSourceSets' property
// in gradle.properties file and re-import your project in IDE.
mingwMain {
}
mingwTest {
}
}
}
// Use the following Gradle tasks to run your application:
// :runReleaseExecutableMingw - without debug symbols
// :runDebugExecutableMingw - with debug symbols
这是一个简单的KT文件:package sample
import kotlinx.coroutines.*
fun main() = runBlocking<Unit> {
val deferred = async(Dispatchers.Unconfined, CoroutineStart.LAZY) {
println("Running Async Unconfined: on thread ${Thread.currentThread().name} has run.")
42
}
val result = deferred.await()
println("Async Unconfined Result is ${result}")
}
我将Maven插件安装在Project Structure |随附模块和屏幕截图。但是,我收到“未解决的引用...”错误。附加的屏幕截图...
请问是否有人可以帮助我解决这个问题?
谢谢
最佳答案
在Project Structure > Modules > Dependencies
选项卡中,选择Runtime
作为范围,这使依赖项仅在运行时可用(通常用于传递性依赖项)。尝试在此处选择Compile
。