I have multi module kotlin gradle project in github here.
One of my sub project introducing-coroutines
with build file build.gradle.kts
file is here
The contents of build.gradle.kts
is -
import org.jetbrains.kotlin.gradle.dsl.Coroutines
import org.jetbrains.kotlin.gradle.tasks.KotlinCompile
plugins {
java
kotlin("jvm") version "1.3.11"
}
group = "chapter2"
version = "1.0-SNAPSHOT"
repositories {
mavenCentral()
}
dependencies {
compile(kotlin("stdlib-jdk8"))
compile(kotlin ("org.jetbrains.kotlinx:kotlinx-coroutines-core:1.1.0"))
testCompile("junit", "junit", "4.12")
}
configure<JavaPluginConvention> {
sourceCompatibility = JavaVersion.VERSION_1_8
}
tasks.withType<KotlinCompile> {
kotlinOptions.jvmTarget = "1.8"
}
kotlin {
experimental {
coroutines = Coroutines.ENABLE
}
}
I'm trying to create my first coroutine program from this link.
import kotlinx.coroutines.*
fun main() {
GlobalScope.launch { // launch new coroutine in background and continue
delay(1000L) // non-blocking delay for 1 second (default time unit is ms)
println("World!") // print after delay
}
println("Hello,") // main thread continues while coroutine is delayed
Thread.sleep(2000L) // block main thread for 2 seconds to keep JVM alive
}
The issue is GlobalScope
is not available in kotlin.coroutines.*
or kotlinx.coroutines.*
. Below is the screenshot -
gradle version - 5.1.1 kotlin version - 1.3.11 kotlinx-coroutines-core - 1.1.0
Can anyone help me the package import details what is package GlobalScope
/ runBlocking
required?