Kotlinx.coroutines: This declaration is experimental and its usage should be marked with '@kotlin.coroutines.ObsoleteCoroutineApi'

Created on 7 Feb 2019  路  11Comments  路  Source: Kotlin/kotlinx.coroutines

Hello,

I have added kotlin experimental features compiler flag to my build.gradle but i still get the warning shown in idea. What i am doing wrong?

  compileKotlin {
        kotlinOptions.freeCompilerArgs += ['-Xuse-experimental=kotlinx.coroutines.ObsoleteCoroutinesApi']
    }
question

Most helpful comment

for me works like this

kotlinOptions {
            jvmTarget = "1.8"
            freeCompilerArgs += [
                    "-Xuse-experimental=kotlinx.coroutines.ExperimentalCoroutinesApi",
                    "-Xuse-experimental=kotlinx.coroutines.ObsoleteCoroutinesApi"]
        }

All 11 comments

Did you reimport your Gradle project into IDEA?

Yes. This happened after i updated kotlin to 1.3.20 and the kotlin compiler plugin.

We also have a multiplatform project with these settings:

all {
            languageSettings {
                useExperimentalAnnotation 'kotlin.contracts.ExperimentalContracts'
                useExperimentalAnnotation 'kotlinx.coroutines.ExperimentalCoroutinesApi'
                useExperimentalAnnotation 'kotlinx.coroutines.ObsoleteCoroutinesApi'
                useExperimentalAnnotation 'kotlinx.serialization.ImplicitReflectionSerializer'
            }
     }

In that project the idea will not show the warnings anymore.

Can you share some more details? I cannot reproduce it with 1.3.20 on the minimal test project that I have.

build.gradle:

plugins {
    id 'java'
    id 'org.jetbrains.kotlin.jvm' version '1.3.21'
}

group 'example'
version '1.0-SNAPSHOT'

sourceCompatibility = 1.8

repositories {
    mavenCentral()
    jcenter()
}

dependencies {
    implementation "org.jetbrains.kotlin:kotlin-stdlib-jdk8"
    implementation "org.jetbrains.kotlinx:kotlinx-serialization-runtime:0.10.0"
    implementation "org.jetbrains.kotlinx:kotlinx-coroutines-core:1.1.1"
}

compileKotlin {
    kotlinOptions.jvmTarget = "1.8"
    kotlinOptions.freeCompilerArgs = ['-Xuse-experimental=kotlinx.serialization.ImplicitReflectionSerializer,kotlinx.coroutines.ObsoleteCoroutinesApi']
}

main.kt

import kotlinx.coroutines.channels.Channel
import kotlinx.coroutines.channels.consumeEach
import kotlinx.coroutines.runBlocking

fun main() = runBlocking {
    Channel<Int>().consumeEach {  }
}

image

@pauliusrum

Make sure to use += instead of = each time you want to define compiler arguments with freeCompilerArgs. Otherwise one gradle script might override the compiler arguments set by another script.

Removing this line from gradle.properties helped:
kotlin.parallel.tasks.in.project=true

I've reported this issue to Kotlin gradle plugin: https://youtrack.jetbrains.com/issue/KT-29928

for me works like this

kotlinOptions {
            jvmTarget = "1.8"
            freeCompilerArgs += [
                    "-Xuse-experimental=kotlinx.coroutines.ExperimentalCoroutinesApi",
                    "-Xuse-experimental=kotlinx.coroutines.ObsoleteCoroutinesApi"]
        }

@evansgelist , thanks. Your solution works like a charm.

@since 1.3.70 use -Xopt-in to replace -Xuse-experimental

 // Groovy DSL
compileKotlin {
    kotlinOptions {
        jvmTarget = "1.8"
        freeCompilerArgs += [
                "-Xopt-in=kotlin.RequiresOptIn",
                "-Xopt-in=kotlin.OptIn"
        ]
    }
}
// Kotlin DSL
tasks.withType<KotlinCompile>().all {
    kotlinOptions.freeCompilerArgs += listOf(
                "-Xopt-in=kotlin.RequiresOptIn",
                "-Xopt-in=kotlin.OptIn"
    )
}
Was this page helpful?
0 / 5 - 0 ratings

Related issues

mhernand40 picture mhernand40  路  3Comments

mttmllns picture mttmllns  路  3Comments

petersamokhin picture petersamokhin  路  3Comments

sky87 picture sky87  路  3Comments

iTanChi picture iTanChi  路  3Comments