|
|
@ -18,9 +18,11 @@ package com.google.samples.apps.nowinandroid
|
|
|
|
|
|
|
|
|
|
|
|
import com.android.build.api.dsl.CommonExtension
|
|
|
|
import com.android.build.api.dsl.CommonExtension
|
|
|
|
import org.gradle.api.Project
|
|
|
|
import org.gradle.api.Project
|
|
|
|
|
|
|
|
import org.gradle.api.provider.Provider
|
|
|
|
|
|
|
|
import org.gradle.kotlin.dsl.assign
|
|
|
|
|
|
|
|
import org.gradle.kotlin.dsl.configure
|
|
|
|
import org.gradle.kotlin.dsl.dependencies
|
|
|
|
import org.gradle.kotlin.dsl.dependencies
|
|
|
|
import org.gradle.kotlin.dsl.withType
|
|
|
|
import org.jetbrains.kotlin.compose.compiler.gradle.ComposeCompilerGradlePluginExtension
|
|
|
|
import org.jetbrains.kotlin.gradle.tasks.KotlinCompile
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
/**
|
|
|
|
* Configure Compose-specific options
|
|
|
|
* Configure Compose-specific options
|
|
|
@ -33,10 +35,6 @@ internal fun Project.configureAndroidCompose(
|
|
|
|
compose = true
|
|
|
|
compose = true
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
composeOptions {
|
|
|
|
|
|
|
|
kotlinCompilerExtensionVersion = libs.findVersion("androidxComposeCompiler").get().toString()
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
dependencies {
|
|
|
|
dependencies {
|
|
|
|
val bom = libs.findLibrary("androidx-compose-bom").get()
|
|
|
|
val bom = libs.findLibrary("androidx-compose-bom").get()
|
|
|
|
add("implementation", platform(bom))
|
|
|
|
add("implementation", platform(bom))
|
|
|
@ -53,48 +51,22 @@ internal fun Project.configureAndroidCompose(
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
tasks.withType<KotlinCompile>().configureEach {
|
|
|
|
extensions.configure<ComposeCompilerGradlePluginExtension> {
|
|
|
|
kotlinOptions {
|
|
|
|
fun Provider<String>.onlyIfTrue() = flatMap { provider { it.takeIf(String::toBoolean) } }
|
|
|
|
freeCompilerArgs += buildComposeMetricsParameters()
|
|
|
|
fun Provider<*>.relativeToRootProject(dir: String) = flatMap {
|
|
|
|
freeCompilerArgs += stabilityConfiguration()
|
|
|
|
rootProject.layout.buildDirectory.dir(projectDir.toRelativeString(rootDir))
|
|
|
|
freeCompilerArgs += strongSkippingConfiguration()
|
|
|
|
}.map { it.dir(dir) }
|
|
|
|
}
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
private fun Project.buildComposeMetricsParameters(): List<String> {
|
|
|
|
project.providers.gradleProperty("enableComposeCompilerMetrics").onlyIfTrue()
|
|
|
|
val metricParameters = mutableListOf<String>()
|
|
|
|
.relativeToRootProject("compose-metrics")
|
|
|
|
val enableMetricsProvider = project.providers.gradleProperty("enableComposeCompilerMetrics")
|
|
|
|
.let(metricsDestination::set)
|
|
|
|
val relativePath = projectDir.relativeTo(rootDir)
|
|
|
|
|
|
|
|
val buildDir = layout.buildDirectory.get().asFile
|
|
|
|
|
|
|
|
val enableMetrics = (enableMetricsProvider.orNull == "true")
|
|
|
|
|
|
|
|
if (enableMetrics) {
|
|
|
|
|
|
|
|
val metricsFolder = buildDir.resolve("compose-metrics").resolve(relativePath)
|
|
|
|
|
|
|
|
metricParameters.add("-P")
|
|
|
|
|
|
|
|
metricParameters.add(
|
|
|
|
|
|
|
|
"plugin:androidx.compose.compiler.plugins.kotlin:metricsDestination=" + metricsFolder.absolutePath,
|
|
|
|
|
|
|
|
)
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
val enableReportsProvider = project.providers.gradleProperty("enableComposeCompilerReports")
|
|
|
|
project.providers.gradleProperty("enableComposeCompilerReports").onlyIfTrue()
|
|
|
|
val enableReports = (enableReportsProvider.orNull == "true")
|
|
|
|
.relativeToRootProject("compose-reports")
|
|
|
|
if (enableReports) {
|
|
|
|
.let(reportsDestination::set)
|
|
|
|
val reportsFolder = buildDir.resolve("compose-reports").resolve(relativePath)
|
|
|
|
|
|
|
|
metricParameters.add("-P")
|
|
|
|
|
|
|
|
metricParameters.add(
|
|
|
|
|
|
|
|
"plugin:androidx.compose.compiler.plugins.kotlin:reportsDestination=" + reportsFolder.absolutePath
|
|
|
|
|
|
|
|
)
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
return metricParameters.toList()
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
private fun Project.stabilityConfiguration() = listOf(
|
|
|
|
stabilityConfigurationFile = rootProject.layout.projectDirectory.file("compose_compiler_config.conf")
|
|
|
|
"-P",
|
|
|
|
|
|
|
|
"plugin:androidx.compose.compiler.plugins.kotlin:stabilityConfigurationPath=${project.rootDir.absolutePath}/compose_compiler_config.conf",
|
|
|
|
|
|
|
|
)
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
private fun Project.strongSkippingConfiguration() = listOf(
|
|
|
|
enableStrongSkippingMode = true
|
|
|
|
"-P",
|
|
|
|
}
|
|
|
|
"plugin:androidx.compose.compiler.plugins.kotlin:experimentalStrongSkipping=true",
|
|
|
|
}
|
|
|
|
)
|
|
|
|
|
|
|
|