title: How do I build and run coroutine basics examples?
body: <p>I'm just trying to follow the instructions on <a href="https://kotlinlang.org/docs/reference/coroutines/basics.html" rel="nofollow noreferrer">this page</a>, which state to run the following code:</p>
  
  <pre><code>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
  }
  </code></pre>
  
  <p>I have this code in a file at my-kotlin-library/src/main/kotlin/coroutines.kt. This is my build.gradle, located in the root my-kotlin-library directory:</p>
  
  <pre><code>plugins {
      kotlin("jvm") version "1.3.21"
  }
  
  repositories {
      jcenter()
  }
  
  dependencies {
      implementation(kotlin("stdlib"))
      implementation("org.jetbrains.kotlinx:kotlinx-coroutines-core:1.1.1")
      testImplementation("junit:junit:4.12")
  }
  </code></pre>
  
  <p>I can build with <code>gradle build</code>, which produces the following artifacts (only showing relevant):</p>
  
  <pre><code>build
  ├── classes
  │   └── kotlin
  │       └── main
  │           ├── CoroutinesKt$main$1.class
  │           ├── CoroutinesKt.class
  │           └── META-INF
  │               └── my-kotlin-library.kotlin_module
  └── libs
      └── my-kotlin-library.jar
  </code></pre>
  
  <p>There are no build errors, yet when I try to run it I get a <code>NoClassDefFoundError</code>:</p>
  
  <pre><code>$ kotlin -cp build/libs/my-kotlin-library.jar CoroutinesKt
  Exception in thread "main" java.lang.NoClassDefFoundError: kotlinx/coroutines/GlobalScope
      at CoroutinesKt.main(coroutines.kt:4)
      at CoroutinesKt.main(coroutines.kt)
      at java.base/jdk.internal.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
      at java.base/jdk.internal.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62)
      at java.base/jdk.internal.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
      at java.base/java.lang.reflect.Method.invoke(Method.java:564)
      at org.jetbrains.kotlin.runner.AbstractRunner.run(runners.kt:61)
      at org.jetbrains.kotlin.runner.Main.run(Main.kt:109)
      at org.jetbrains.kotlin.runner.Main.main(Main.kt:119)
  Caused by: java.lang.ClassNotFoundException: kotlinx.coroutines.GlobalScope
      at java.base/java.net.URLClassLoader.findClass(URLClassLoader.java:466)
      at java.base/java.lang.ClassLoader.loadClass(ClassLoader.java:566)
      at java.base/java.lang.ClassLoader.loadClass(ClassLoader.java:499)
      ... 9 more
  </code></pre>
  
  <p>I found the coroutines jar file and tried including it in the classpath also:</p>
  
  <pre><code>$ kotlin -cp ~/.gradle/caches/modules-2/files-2.1/org.jetbrains.kotlinx/kotlinx-coroutines-core/1.1.1/3d2b7321cdef9ebf9cb7729ea4f75a6f6457df86/kotlinx-coroutines-core-1.1.1.jar:build/libs/my-kotlin-library.jar CoroutinesKt
  </code></pre>
  
  <p>Unfortunately this produced the same error. I must have something configured incorrectly, but I can't find a good example of building and running using coroutines outside of Android Studio or IntelliJ IDEA.</p>