From e4681fce31a6f15d8544b23b9e3fc44b95ba0096 Mon Sep 17 00:00:00 2001 From: Alex Vanyo Date: Fri, 13 Dec 2024 15:08:18 -0800 Subject: [PATCH] Add androidx.lint:lint-gradle to build-logic Change-Id: I95a0e1f5ae5d78d3725ab20031fe268515a50153 --- build-logic/convention/build.gradle.kts | 3 ++- .../kotlin/AndroidApplicationJacocoConventionPlugin.kt | 4 ++-- .../google/samples/apps/nowinandroid/AndroidCompose.kt | 8 +++++--- .../com/google/samples/apps/nowinandroid/Badging.kt | 4 ++-- build-logic/settings.gradle.kts | 7 +++++++ gradle/libs.versions.toml | 3 +++ 6 files changed, 21 insertions(+), 8 deletions(-) diff --git a/build-logic/convention/build.gradle.kts b/build-logic/convention/build.gradle.kts index b4306b013..6d0237010 100644 --- a/build-logic/convention/build.gradle.kts +++ b/build-logic/convention/build.gradle.kts @@ -15,10 +15,10 @@ */ import org.jetbrains.kotlin.gradle.dsl.JvmTarget -import org.jetbrains.kotlin.gradle.tasks.KotlinCompile plugins { `kotlin-dsl` + alias(libs.plugins.android.lint) } group = "com.google.samples.apps.nowinandroid.buildlogic" @@ -46,6 +46,7 @@ dependencies { compileOnly(libs.ksp.gradlePlugin) compileOnly(libs.room.gradlePlugin) implementation(libs.truth) + lintChecks(libs.androidx.lint.gradle) } tasks { diff --git a/build-logic/convention/src/main/kotlin/AndroidApplicationJacocoConventionPlugin.kt b/build-logic/convention/src/main/kotlin/AndroidApplicationJacocoConventionPlugin.kt index ac385b0d9..5bd58fabe 100644 --- a/build-logic/convention/src/main/kotlin/AndroidApplicationJacocoConventionPlugin.kt +++ b/build-logic/convention/src/main/kotlin/AndroidApplicationJacocoConventionPlugin.kt @@ -14,8 +14,8 @@ * limitations under the License. */ +import com.android.build.api.dsl.ApplicationExtension import com.android.build.api.variant.ApplicationAndroidComponentsExtension -import com.android.build.gradle.internal.dsl.BaseAppModuleExtension import com.google.samples.apps.nowinandroid.configureJacoco import org.gradle.api.Plugin import org.gradle.api.Project @@ -25,7 +25,7 @@ class AndroidApplicationJacocoConventionPlugin : Plugin { override fun apply(target: Project) { with(target) { pluginManager.apply("jacoco") - val androidExtension = extensions.getByType() + val androidExtension = extensions.getByType() androidExtension.buildTypes.configureEach { enableAndroidTestCoverage = true diff --git a/build-logic/convention/src/main/kotlin/com/google/samples/apps/nowinandroid/AndroidCompose.kt b/build-logic/convention/src/main/kotlin/com/google/samples/apps/nowinandroid/AndroidCompose.kt index ffb6358c3..d32470dac 100644 --- a/build-logic/convention/src/main/kotlin/com/google/samples/apps/nowinandroid/AndroidCompose.kt +++ b/build-logic/convention/src/main/kotlin/com/google/samples/apps/nowinandroid/AndroidCompose.kt @@ -53,8 +53,10 @@ internal fun Project.configureAndroidCompose( extensions.configure { fun Provider.onlyIfTrue() = flatMap { provider { it.takeIf(String::toBoolean) } } - fun Provider<*>.relativeToRootProject(dir: String) = flatMap { - rootProject.layout.buildDirectory.dir(projectDir.toRelativeString(rootDir)) + fun Provider<*>.relativeToRootProject(dir: String) = map { + isolated.rootProject.projectDirectory + .dir("build") + .dir(projectDir.toRelativeString(rootDir)) }.map { it.dir(dir) } project.providers.gradleProperty("enableComposeCompilerMetrics").onlyIfTrue() @@ -66,6 +68,6 @@ internal fun Project.configureAndroidCompose( .let(reportsDestination::set) stabilityConfigurationFile = - rootProject.layout.projectDirectory.file("compose_compiler_config.conf") + isolated.rootProject.projectDirectory.file("compose_compiler_config.conf") } } diff --git a/build-logic/convention/src/main/kotlin/com/google/samples/apps/nowinandroid/Badging.kt b/build-logic/convention/src/main/kotlin/com/google/samples/apps/nowinandroid/Badging.kt index ac3b694e8..886c70625 100644 --- a/build-logic/convention/src/main/kotlin/com/google/samples/apps/nowinandroid/Badging.kt +++ b/build-logic/convention/src/main/kotlin/com/google/samples/apps/nowinandroid/Badging.kt @@ -140,7 +140,7 @@ fun Project.configureBadgingTasks( val updateBadgingTaskName = "update${capitalizedVariantName}Badging" tasks.register(updateBadgingTaskName) { - from(generateBadging.get().badging) + from(generateBadging.map(GenerateBadgingTask::badging)) into(project.layout.projectDirectory) } @@ -148,7 +148,7 @@ fun Project.configureBadgingTasks( tasks.register(checkBadgingTaskName) { goldenBadging = project.layout.projectDirectory.file("${variant.name}-badging.txt") - generatedBadging = generateBadging.get().badging + generatedBadging.set(generateBadging.flatMap(GenerateBadgingTask::badging)) this.updateBadgingTaskName = updateBadgingTaskName diff --git a/build-logic/settings.gradle.kts b/build-logic/settings.gradle.kts index b359a5207..ff96cc84a 100644 --- a/build-logic/settings.gradle.kts +++ b/build-logic/settings.gradle.kts @@ -14,6 +14,13 @@ * limitations under the License. */ +pluginManagement { + repositories { + gradlePluginPortal() + google() + } +} + dependencyResolutionManagement { repositories { google { diff --git a/gradle/libs.versions.toml b/gradle/libs.versions.toml index 6e7eb4321..8c4a2af45 100644 --- a/gradle/libs.versions.toml +++ b/gradle/libs.versions.toml @@ -15,6 +15,7 @@ androidxDataStore = "1.1.1" androidxEspresso = "3.6.1" androidxHiltNavigationCompose = "1.2.0" androidxLifecycle = "2.8.7" +androidxLintGradle = "1.0.0-alpha03" androidxMacroBenchmark = "1.3.3" androidxMetrics = "1.0.0-beta01" androidxNavigation = "2.8.5" @@ -92,6 +93,7 @@ androidx-hilt-navigation-compose = { group = "androidx.hilt", name = "hilt-navig androidx-lifecycle-runtimeCompose = { group = "androidx.lifecycle", name = "lifecycle-runtime-compose", version.ref = "androidxLifecycle" } androidx-lifecycle-runtimeTesting = { group = "androidx.lifecycle", name = "lifecycle-runtime-testing", version.ref = "androidxLifecycle" } androidx-lifecycle-viewModelCompose = { group = "androidx.lifecycle", name = "lifecycle-viewmodel-compose", version.ref = "androidxLifecycle" } +androidx-lint-gradle = { group = "androidx.lint", name = "lint-gradle", version.ref = "androidxLintGradle" } androidx-metrics = { group = "androidx.metrics", name = "metrics-performance", version.ref = "androidxMetrics" } androidx-navigation-compose = { group = "androidx.navigation", name = "navigation-compose", version.ref = "androidxNavigation" } androidx-navigation-testing = { group = "androidx.navigation", name = "navigation-testing", version.ref = "androidxNavigation" } @@ -161,6 +163,7 @@ room-gradlePlugin = { group = "androidx.room", name = "room-gradle-plugin", vers [plugins] android-application = { id = "com.android.application", version.ref = "androidGradlePlugin" } android-library = { id = "com.android.library", version.ref = "androidGradlePlugin" } +android-lint = { id = "com.android.lint", version.ref = "androidGradlePlugin" } android-test = { id = "com.android.test", version.ref = "androidGradlePlugin" } baselineprofile = { id = "androidx.baselineprofile", version.ref = "androidxMacroBenchmark"} compose = { id = "org.jetbrains.kotlin.plugin.compose", version.ref = "kotlin" }