1
0

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?

Kotlin coroutine Intellij Idea dependencies

Last updated at Posted at 2024-11-04

build.gradle.ktsファイルのplugins、dependencies内に設定するバージョン数は、下記サイトで最新のバージョン数を確認し設定する
https://github.com/Kotlin/kotlinx.coroutines?tab=readme-ov-file#gradle

※dependencies内に設定するバージョン数は、kotlinのバージョン数と同じにすれば良いわけではなく、下記サイトで設定できるバージョン数を確認し設定する
https://mvnrepository.com/artifact/org.jetbrains.kotlinx/kotlinx-coroutines-core

build.gradle.ktsファイルを変更した後、画面右上の[Gradleの変更を読み込む]アイコンをクリックして更新する
ショートカットキーは、Ctrl + Shift + O

build.gradle.kts 一部抜粋
plugins {
    kotlin("jvm") version "2.0.0"
}

dependencies {
    implementation("org.jetbrains.kotlinx:kotlinx-coroutines-core:1.9.0")
}

以下設定例
Intellij Ideaバージョン 2022.3.3を使用

build.gradle.kts
import org.jetbrains.kotlin.gradle.tasks.KotlinCompile

plugins {
    kotlin("jvm") version "2.0.0"
    application
}

group = "org.example"
version = "1.0-SNAPSHOT"

repositories {
    mavenCentral()
}

dependencies {
    testImplementation(kotlin("test"))
    implementation("org.jetbrains.kotlinx:kotlinx-coroutines-core:1.9.0")
}

tasks.test {
    useJUnitPlatform()
}

tasks.withType<KotlinCompile> {
    kotlinOptions.jvmTarget = "1.8"
}

application {
    mainClass.set("MainKt")
}
Main.kt
import kotlinx.coroutines.*

suspend fun main() = coroutineScope {
    launch {
        delay(1000)
        println("Kotlin Coroutines World!")
    }
    println("Hello")
}
1
0
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
1
0

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?