New to Kotlin here. I was trying to follow the coroutines sample code https://kotlinlang.org/docs/tutorials/coroutines-basic-jvm.html but wasn’t able to get the code to even compile. It failed on unresolved reference: kotlinx
I have updated the gradle script accordingly as well. What am I missing? Thanks.
Using Intellij CE 2017.2, and Kotlin is v1.1.51
buildscript {
ext.kotlin_version = '1.1.51'
repositories {
jcenter()
}
dependencies {
classpath "org.jetbrains.kotlin:kotlin-gradle-plugin:$kotlin_version"
classpath "org.jetbrains.kotlinx:kotlinx-coroutines-core:$kotlin_version"
}
}
apply plugin: 'kotlin'
kotlin {
experimental {
coroutines 'enable'
}
}
repositories {
jcenter()
}
sourceSets {
main.kotlin.srcDirs += 'src/main/kotlin'
}
dependencies {
compile "org.jetbrains.kotlin:kotlin-stdlib-jre8:$kotlin_version"
compile "org.jetbrains.kotlinx:kotlinx-coroutines-core:$kotlin_version"
}
import kotlin.coroutines.experimental.*
fun main(args: Array<String>) {
println("Start")
// Start a coroutine
launch(CommonPool) {
delay(1000)
println("Hello")
}
Thread.sleep(2000) // wait for 2 seconds
println("Stop")
}