https://kotlinlang.org logo
#compose
Title
# compose
v

vide

01/19/2023, 9:03 AM
I just updated to Electric Eel and tried to upgrade to AGP 7.4.0, but it seems to have a regression breaking compose metrics: custom
freeCompilerArgs
are for reason applied twice and building fails with
Copy code
Multiple values are not allowed for plugin option androidx.compose.compiler.plugins.kotlin:metricsDestination
I'm using compose metrics like this:
Copy code
subprojects {
    tasks.withType(org.jetbrains.kotlin.gradle.tasks.KotlinCompile).configureEach {
        kotlinOptions {
            freeCompilerArgs += [
                    "-P",
                    "plugin:androidx.compose.compiler.plugins.kotlin:reportsDestination=" +
                            project.buildDir.absolutePath + "/compose_metrics"
            ]
            freeCompilerArgs += [
                    "-P",
                    "plugin:androidx.compose.compiler.plugins.kotlin:metricsDestination=" +
                            project.buildDir.absolutePath + "/compose_metrics"
            ]
        }
    }
}
from https://chris.banes.me/posts/composable-metrics/
I think this was broken by this fix? https://issuetracker.google.com/issues/247544167 EDIT: hmm, maybe it's something else
Or is my approach to setting the metricsDestination option fundamentally wrong?
a

Aaron Pramana

01/23/2023, 1:24 AM
Copy code
pluginOptions.add(org.jetbrains.kotlin.gradle.plugin.CompilerPluginConfig().apply {
     addPluginArgument(
         "androidx.compose.compiler.plugins.kotlin",
         org.jetbrains.kotlin.gradle.plugin.SubpluginOption(
             "reportsDestination",
             project.buildDir.absolutePath + "/compose_metrics"
         )
     )
     addPluginArgument(
         "androidx.compose.compiler.plugins.kotlin",
         org.jetbrains.kotlin.gradle.plugin.SubpluginOption(
             "metricsDestination",
             project.buildDir.absolutePath + "/compose_metrics"
         )
     )
 })
s

scana

02/09/2023, 1:16 PM
This issue is caused by KAPT duplicating freeCompilerArgs params. To fix this, replace:
Copy code
tasks.withType(org.jetbrains.kotlin.gradle.tasks.KotlinCompile).configureEach {
with:
Copy code
tasks.withType(org.jetbrains.kotlin.gradle.tasks.KotlinCompile)
  .matching { it !instanceof org.jetbrains.kotlin.gradle.internal.KaptGenerateStubsTask }
  .configureEach {
This way they won't be picked up by KAPT. Resources: https://youtrack.jetbrains.com/issue/KT-55565/Consider-de-duping-or-blocking-standard-addition-of-freeCompilerArgs-to-KaptGenerateStubsTask https://github.com/slackhq/slack-gradle-plugin/pull/193 https://github.com/slackhq/slack-gradle-plugin/commit/1c471417542397807383233c33c2122a261a7303
v

vide

02/09/2023, 1:32 PM
woah, good job figuring out the root cause!
I tried to dig a little but never figured out what was causing it
46 Views