Kotlin / kotlinx.coroutines

Library support for Kotlin coroutines
Apache License 2.0
13.06k stars 1.85k forks source link

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

Closed pauliusrum closed 5 years ago

pauliusrum commented 5 years ago

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']
    }
elizarov commented 5 years ago

Did you reimport your Gradle project into IDEA?

pauliusrum commented 5 years ago

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

pauliusrum commented 5 years ago

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.

elizarov commented 5 years ago

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

pauliusrum commented 5 years ago

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

jcornaz commented 5 years ago

@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.

pauliusrum commented 5 years ago

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

elizarov commented 5 years ago

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

evansgelist commented 5 years ago

for me works like this

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

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

mochadwi commented 4 years ago

@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"
    )
}
ursusursus commented 3 years ago

when I use what @mochadwi said, I get > Task :texts:impl:compileDebugKotlin w: Class kotlin.OptIn is not an opt-in requirement marker˙. What does it mean? Is OptIn hooked up implicitly?

KhaderMurtaja commented 3 years ago

for me works like this

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

In which file within the FLutter application ??

CHANDRAMOHANnegi commented 1 year ago

Change to the distributionUrl in /android/gradle/wrapper/gradle-wrapper.properties fixed the issue for me.

distributionUrl=https://services.gradle.org/distributions/gradle-7.5.1-all.zip