Hey! I’m receiving this warnings (not always, didn...
# gradle
g
Hey! I’m receiving this warnings (not always, didn’t found a pattern):
> Task module123compileDebugKotlin
warning: opt-in requirement marker kotlinx.coroutines.FlowPreview is unresolved. Please make sure it’s present in the module dependencies
warning: opt-in requirement marker kotlinx.coroutines.ExperimentalCoroutinesApi is unresolved. Please make sure it’s present in the module dependencies
warning: opt-in requirement marker kotlinx.serialization.ExperimentalSerializationApi is unresolved. Please make sure it’s present in the module dependencies
But I’ve a gradle script with it:
Copy code
private fun KotlinJvmOptions.addOptions(options: List<String> = emptyList()) {
    jvmTarget = JavaVersion.VERSION_11.toString()
    freeCompilerArgs = freeCompilerArgs + listOf(
        "-opt-in=kotlin.RequiresOptIn",
        "-opt-in=kotlin.Experimental",
        "-opt-in=kotlinx.coroutines.FlowPreview",
        "-opt-in=kotlinx.coroutines.ExperimentalCoroutinesApi",
        "-opt-in=kotlinx.serialization.ExperimentalSerializationApi"
    ) + options
}
Why is it throwing that warning? 🤔
It’s applied like:
Copy code
internal fun LibraryExtension.addKotlinJvmOptions(options: List<String> = emptyList()) {
    (this as ExtensionAware).extensions.configure<KotlinJvmOptions>("kotlinOptions") { addOptions(options) }
}

internal fun BaseAppModuleExtension.addKotlinJvmOptions(options: List<String> = emptyList()) {
    (this as ExtensionAware).extensions.configure<KotlinJvmOptions>("kotlinOptions") { addOptions(options) }
}
v
From the message I'd guess because you do not have coroutines and serialization in your dependencies.
g
But I do have them imported, for instance:
Copy code
import kotlinx.coroutines.FlowPreview

@FlowPreview
....
(actually I can remove them all now because I’m using stable versions, but they’re there 🤔 )
v
Well, you answered yourself then. If you use newer versions of these libs that do not have those opt-in switches anymore the message still makes sense.
g
Ok, makes sense. Thanks @Vampire 😉
Ok I’ve found one that still needs @ExperimentalSerializationApi:
Copy code
@ExperimentalSerializationApi
@JvmName("create")
fun StringFormat.asConverterFactory(contentType: MediaType): Converter.Factory {
  return Factory(contentType, FromString(this))
}
If I remove it no warning is thrown in the IDE, only in the console build output
If I add it (and in the gradle script also) it throws randomly:
warning: opt-in requirement marker kotlinx.serialization.ExperimentalSerializationApi is unresolved. Please make sure it’s present in the module dependencies
my script it’s applied to all “app” and “libs” modules
ok i got it, it’s what you said, I was using it in module A but not in module B and this addOptions logic is applied regardless, so yeah, if we do not import the library that needs that flag it will show that warning 🙂
m
971 Views