Hi i want to passing this kotlin argument only for...
# android
d
Hi i want to passing this kotlin argument only for my unit test build
Copy code
kotlinOptions {
    freeCompilerArgs += [
            '-Xsam-conversions=class',
    ]
}
Any one have clue how i can achieve it ? Thank you in advance
e
totally untested but maybe something like
Copy code
tasks.withType(KotlinCompile).matching { it.name.contains('Test') }.configureEach {
    kotlinOptions.freeCompilerArgs += [ ... ]
}
could work
j
I usually use this approach:
Copy code
tasks {
    val prodOptIns = listOf("kotlin.RequiresOptIn")
    val testOptIns =
        prodOptIns +
            listOf("kotlinx.coroutines.ExperimentalCoroutinesApi", "kotlinx.coroutines.FlowPreview")

    compileKotlin {
        kotlinOptions { freeCompilerArgs = freeCompilerArgs + prodOptIns.map { "-Xopt-in=$it" } }
    }
    compileTestKotlin {
        kotlinOptions { freeCompilerArgs = freeCompilerArgs + testOptIns.map { "-Xopt-in=$it" } }
    }
}
Works like a charm
d
thanks for the suggestion guys, I will try it later 🙏
e
fyi joe's suggestion will work for plain JVM projects but not Android projects
🙏 1
j
Oh wow, TIL. It's been a while since I did Android, forgot that the tasks are named differently.