I just updated to Electric Eel and tried to upgrad...
# compose
v
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
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
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
woah, good job figuring out the root cause!
I tried to dig a little but never figured out what was causing it