my build.gradle:
buildscript {
ext.kotlin_version = '1.3.0-rc-190'
repositories {
mavenCentral()
}
dependencies {
classpath "org.jetbrains.kotlin:kotlin-gradle-plugin:$kotlin_version"
}
}
apply plugin: "kotlin"
group 'com.lxj'
version '1.0-SNAPSHOT'
sourceCompatibility = 1.8
repositories {
mavenCentral()
}
dependencies {
implementation "org.jetbrains.kotlin:kotlin-stdlib-jdk8:${kotlin_version}"
testCompile group: 'junit', name: 'junit', version: '4.12'
implementation 'org.jetbrains.kotlinx:kotlinx-coroutines-core:1.0.0-RC1'
}
compileKotlin {
kotlinOptions.jvmTarget = "1.8"
}
compileTestKotlin {
kotlinOptions.jvmTarget = "1.8"
}
my code is:
fun main(args: Array<String>) {
GlobalScope.launch{
print("I am from coroutines")
}
}
the console output:
Exception in thread "main" java.lang.NoClassDefFoundError: kotlin/coroutines/jvm/internal/CoroutineImpl
at java.lang.ClassLoader.defineClass1(Native Method)
at java.lang.ClassLoader.defineClass(ClassLoader.java:763)
at java.security.SecureClassLoader.defineClass(SecureClassLoader.java:142)
at java.net.URLClassLoader.defineClass(URLClassLoader.java:467)
at java.net.URLClassLoader.access$100(URLClassLoader.java:73)
at java.net.URLClassLoader$1.run(URLClassLoader.java:368)
at java.net.URLClassLoader$1.run(URLClassLoader.java:362)
at java.security.AccessController.doPrivileged(Native Method)
at java.net.URLClassLoader.findClass(URLClassLoader.java:361)
at java.lang.ClassLoader.loadClass(ClassLoader.java:424)
at sun.misc.Launcher$AppClassLoader.loadClass(Launcher.java:349)
at java.lang.ClassLoader.loadClass(ClassLoader.java:357)
at start.AKt.main(a.kt:13)
Caused by: java.lang.ClassNotFoundException: kotlin.coroutines.jvm.internal.CoroutineImpl
at java.net.URLClassLoader.findClass(URLClassLoader.java:381)
at java.lang.ClassLoader.loadClass(ClassLoader.java:424)
at sun.misc.Launcher$AppClassLoader.loadClass(Launcher.java:349)
at java.lang.ClassLoader.loadClass(ClassLoader.java:357)
... 13 more
Is it still a problem with corouines 1.0.0 and Kotlin 1.3?
@qwwdfsad yes.
Could you please provide a sample project which reproduces the problem?
I've created a project with the same build.gradle (but with version 1.3 and 1.0.0) and it works properly
Same issue
import kotlinx.coroutines.GlobalScope
import kotlinx.coroutines.launch
fun main(args: Array<String>) {
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
}
it works after I update IDEA kotlin plugin to 1.3 and restart IDEA锛宐efore the plugin version is 1.2.65.

@li-xiaojun , It works for me, thanks!
Updating kotlin to 1.3 and restarting gave me another error (using the quickstart code on https://ktor.io/quickstart/index.html).
adding
implementation 'org.jetbrains.kotlinx:kotlinx-coroutines-core:1.0.0-RC1'
to
dependencies {
}
fixed it for me
@Nadim96 that fixed it for me as well! I should have thought of that but I'm so glad to have found your comment. Thank you!
got this error when using spring webflux corouter (added implementation("org.jetbrains.kotlinx:kotlinx-coroutines-core:1.3.2")
in gradle)
Most helpful comment
it works after I update IDEA kotlin plugin to 1.3 and restart IDEA锛宐efore the plugin version is 1.2.65.
