Justin Breitfeller
12/14/2022, 3:29 PMval 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.