Ciaran Sloan
11/07/2023, 10:21 AMkotlinOptions
block, but since updating kotlin and AGP this seems to no longer resolve. Im reading the docs and following whats specified here, but getting the error Task with name 'compileKotlin' not found in project
. I'm declaring this in the build.gradle.kts
of a kmp module.
Has anyone any suggestions where I might be going wrong?Ciaran Sloan
11/07/2023, 10:24 AMcompileKotlinIosArm64, compileKotlinIosSimulatorArm64, compileKotlinIosX64, compileKotlinMetadata, compileLint, compileTestKotlinIosArm64, compileTestKotlinIosSimulatorArm64, compileTestKotlinIosX64
Curious as to how best to declare these compiler options without having to write this for each of these compile kotlin tasks?Ciaran Sloan
11/07/2023, 10:28 AMOptIn
APIs across these modules and I want to opt into these via compiler args. I'm trying to write this once in the projectVampire
11/07/2023, 10:42 AMcompileKotlin
task.
The correct example should be something like
tasks.withType<KotlinCompilationTask<*>>().configureEach {
...
}
Ciaran Sloan
11/07/2023, 10:46 AMmbonnin
11/07/2023, 10:46 AMkotlin {
targets.all {
compilations.all {
compilerOptions.configure {
}
}
}
}
Ciaran Sloan
11/07/2023, 10:48 AMkotlin
lambda right? So how can I do this in a multi module setup?mbonnin
11/07/2023, 10:48 AMkotlin
is the top level extension for KGPmbonnin
11/07/2023, 10:49 AMextensions.findByName("kotlin") as KotlinMultiplatformExtension
mbonnin
11/07/2023, 10:49 AMkotlin {}
in a build scriptCiaran Sloan
11/07/2023, 10:50 AMextensions.findByType<KotlinAndroidProjectExtension>()?.apply {
jvmToolchain(17)
}
extensions.findByType<KotlinMultiplatformExtension>()?.apply {
jvmToolchain(17)
}
Ciaran Sloan
11/07/2023, 10:50 AMCiaran Sloan
11/07/2023, 10:50 AMCiaran Sloan
11/07/2023, 10:53 AMclass KotlinConventionPlugin : Plugin<Project> {
override fun apply(target: Project) {
with(target) {
tasks.withType<KotlinCompilationTask<*>>().configureEach {
compilerOptions.optIn.addAll(OPT_IN_FLAGS)
}
extensions.findByType<KotlinAndroidProjectExtension>()?.apply {
jvmToolchain(17)
}
extensions.findByType<KotlinMultiplatformExtension>()?.apply {
jvmToolchain(17)
}
}
}
}
mbonnin
11/07/2023, 10:54 AMkotlin {
targets.all {
sourceSets.all {
languageSettings.optIn("org.mylibrary.OptInAnnotation")
}
}
}
Ciaran Sloan
11/07/2023, 10:55 AMmbonnin
11/07/2023, 10:55 AMCiaran Sloan
11/07/2023, 10:55 AMmbonnin
11/07/2023, 10:56 AMmbonnin
11/07/2023, 10:56 AMmy use case has a mix of android and kmp projectsThe docs has separate instructions for both, I'm not sure why TBH
Ciaran Sloan
11/07/2023, 10:57 AM