https://kotlinlang.org logo
#gradle
Title
# gradle
p

PHondogo

11/12/2023, 4:48 PM
How can I specify Kotlin compiler options for compileCommonMainKotlinMetadata task (klib generation)? I need to supress warnings about expect/actual usage. I'm setting flag -Xexpect-actual-classes to metadata target like this:
Copy code
mpp.targets.getByName("metadata").compilations.forEach {
  it.compilerOptions.options.freeCompilerArgs.add("-Xexpect-actual-classes")
}
but still see warnings
t

tapchicoma

11/12/2023, 9:40 PM
Alternative could be:
Copy code
tasks.named<org.jetbrains.kotlin.gradle.tasks.KotlinCompilationTask<*>>("compileCommonMainKotlinMetadata") {
    compilerOptions.freeCompilerArgs.add("...")
}
p

PHondogo

11/13/2023, 3:42 PM
@tapchicoma thanks! Alternative is working. But why it is not applying using requested variant?
a

Anton Lakotka [JB]

11/13/2023, 6:27 PM
Try to avoid terminal operators such as
forEach
when iterating over Gradle-specific collections such as compilations. Instead, use
configureEach
or
all
For example like this:
Copy code
kotlin {
    metadata {
        compilations.configureEach {
            compilerOptions.options.freeCompilerArgs.add("-Xexpect-actual-classes")
        }
    }
}
p

PHondogo

11/13/2023, 6:52 PM
@Anton Lakotka [JB] Thanks! Now working both variants.