Hi all, I have a desire to create a task to genera...
# android
j
Hi all, I have a desire to create a task to generate compose metric reports. The way this is done is by providing compilerArgs to the appropriate KotlinCompile task. This is how I managed to do it. Is there a better way ?
Copy code
val compileReleaseKotlin by lazy {
    tasks.named<KotlinCompile>("compileReleaseKotlin")
}

var addComposeMetricKotlinCompilerArgs = false
tasks.register<DefaultTask>("generateComposeMetricsReport") {
    if (android.buildFeatures.compose == true) {
        addComposeMetricKotlinCompilerArgs = true
        finalizedBy(compileReleaseKotlin)
    }
}

project.gradle.taskGraph.whenReady {
    if (addComposeMetricKotlinCompilerArgs) {
        compileReleaseKotlin.configure {
            val pluginSpec = "plugin:androidx.compose.compiler.plugins.kotlin"
            val outputDir = project.buildDir.absolutePath + "/compose_compiler"
            outputs.dir(outputDir)
            kotlinOptions.freeCompilerArgs += listOf(
                "-P",
                "$pluginSpec:reportsDestination=$outputDir",
                "-P",
                "$pluginSpec:metricsDestination=$outputDir",
            )
        }
    }
}
In particular, the taskGraph whenReady callback feels heavy handed, but I’m not sure if there is a better way.