From 9a6d7d267ade5051558bb49a0608adb71d445875 Mon Sep 17 00:00:00 2001 From: Harsh Shandilya Date: Tue, 5 Mar 2024 19:11:16 +0530 Subject: [PATCH] feat(build): add androidx.lint checks to build-logic --- build-logic/build.gradle.kts | 9 ++++++- build-logic/lint-baseline.xml | 26 +++++++++++++++++++ build-logic/settings.gradle.kts | 9 +++++++ .../claw/gradle/ApplicationPlugin.kt | 24 +++++++---------- .../claw/gradle/signing/AppSigning.kt | 4 +-- gradle/libs.versions.toml | 2 ++ 6 files changed, 57 insertions(+), 17 deletions(-) create mode 100644 build-logic/lint-baseline.xml diff --git a/build-logic/build.gradle.kts b/build-logic/build.gradle.kts index bddfbf73..5115a3d5 100644 --- a/build-logic/build.gradle.kts +++ b/build-logic/build.gradle.kts @@ -4,7 +4,10 @@ * license that can be found in the LICENSE file or at * https://opensource.org/licenses/MIT. */ -plugins { `kotlin-dsl` } +plugins { + `kotlin-dsl` + alias(libs.plugins.android.lint) +} kotlin.jvmToolchain(17) @@ -61,6 +64,8 @@ gradlePlugin { } } +lint.baseline = project.file("lint-baseline.xml") + dependencies { implementation(libs.build.agp) implementation(libs.build.cachefix) @@ -72,4 +77,6 @@ dependencies { // Expose the generated version catalog API to the plugin. implementation(files(libs::class.java.superclass.protectionDomain.codeSource.location)) + + lintChecks(libs.androidx.lint) } diff --git a/build-logic/lint-baseline.xml b/build-logic/lint-baseline.xml new file mode 100644 index 00000000..bb8fe114 --- /dev/null +++ b/build-logic/lint-baseline.xml @@ -0,0 +1,26 @@ + + + + + + + + + + + + diff --git a/build-logic/settings.gradle.kts b/build-logic/settings.gradle.kts index 98503983..8eb9f82e 100644 --- a/build-logic/settings.gradle.kts +++ b/build-logic/settings.gradle.kts @@ -23,6 +23,14 @@ pluginManagement { includeModule("org.gradle.kotlin", "gradle-kotlin-dsl-plugins") } } + exclusiveContent { + forRepository { google() } + filter { + includeGroup("androidx.databinding") + includeGroupByRegex("com.android.*") + includeGroup("com.google.testing.platform") + } + } mavenCentral { mavenContent { releasesOnly() } } } } @@ -33,6 +41,7 @@ dependencyResolutionManagement { forRepository(::google) filter { includeGroup("androidx.databinding") + includeGroup("androidx.lint") includeGroupByRegex("com.android.*") includeGroup("com.google.testing.platform") } diff --git a/build-logic/src/main/kotlin/dev/msfjarvis/claw/gradle/ApplicationPlugin.kt b/build-logic/src/main/kotlin/dev/msfjarvis/claw/gradle/ApplicationPlugin.kt index 7c92b518..d6887300 100644 --- a/build-logic/src/main/kotlin/dev/msfjarvis/claw/gradle/ApplicationPlugin.kt +++ b/build-logic/src/main/kotlin/dev/msfjarvis/claw/gradle/ApplicationPlugin.kt @@ -1,5 +1,5 @@ /* - * Copyright © 2022-2023 Harsh Shandilya. + * Copyright © 2022-2024 Harsh Shandilya. * Use of this source code is governed by an MIT-style * license that can be found in the LICENSE file or at * https://opensource.org/licenses/MIT. @@ -33,26 +33,22 @@ class ApplicationPlugin : Plugin { buildConfig = true } - buildTypes { - all { - setProguardFiles( - listOf( - "proguard-android-optimize.pro", - "proguard-rules.pro", - "proguard-rules-missing-classes.pro", - ) + buildTypes.configureEach { + setProguardFiles( + listOf( + "proguard-android-optimize.pro", + "proguard-rules.pro", + "proguard-rules-missing-classes.pro", ) - } - named("release") { + ) + if (name == "release") { isMinifyEnabled = !project.providers.environmentVariable("DISABLE_MINIFY").isPresent - } - named("debug") { + } else if (name == "debug") { applicationIdSuffix = ".debug" versionNameSuffix = "-debug" isMinifyEnabled = false } } - project.configureBuildSigning() } } diff --git a/build-logic/src/main/kotlin/dev/msfjarvis/claw/gradle/signing/AppSigning.kt b/build-logic/src/main/kotlin/dev/msfjarvis/claw/gradle/signing/AppSigning.kt index e40100e7..553f7bb4 100644 --- a/build-logic/src/main/kotlin/dev/msfjarvis/claw/gradle/signing/AppSigning.kt +++ b/build-logic/src/main/kotlin/dev/msfjarvis/claw/gradle/signing/AppSigning.kt @@ -1,5 +1,5 @@ /* - * Copyright © 2022 Harsh Shandilya. + * Copyright © 2022-2024 Harsh Shandilya. * Use of this source code is governed by an MIT-style * license that can be found in the LICENSE file or at * https://opensource.org/licenses/MIT. @@ -31,7 +31,7 @@ internal fun Project.configureBuildSigning() { } } val signingConfig = signingConfigs.getByName("release") - buildTypes.all { setSigningConfig(signingConfig) } + buildTypes.configureEach { setSigningConfig(signingConfig) } } } } diff --git a/gradle/libs.versions.toml b/gradle/libs.versions.toml index e513299f..232b48a7 100644 --- a/gradle/libs.versions.toml +++ b/gradle/libs.versions.toml @@ -44,6 +44,7 @@ androidx-core-splashscreen = "androidx.core:core-splashscreen:1.1.0-alpha02" androidx-lifecycle-common = { module = "androidx.lifecycle:lifecycle-common", version.ref = "lifecycle" } androidx-lifecycle-compose = { module = "androidx.lifecycle:lifecycle-viewmodel-compose", version.ref = "lifecycle" } androidx-lifecycle-runtime = { module = "androidx.lifecycle:lifecycle-runtime", version.ref = "lifecycle" } +androidx-lint = "androidx.lint:lint-gradle:1.0.0-alpha01" androidx-navigation-compose = "androidx.navigation:navigation-compose:2.8.0-alpha03" androidx-paging-compose = "androidx.paging:paging-compose:3.3.0-alpha03" androidx-profileinstaller = "androidx.profileinstaller:profileinstaller:1.4.0-alpha01" @@ -108,6 +109,7 @@ unfurl = "me.saket.unfurl:unfurl:1.7.0" [plugins] aboutlibraries = { id = "com.mikepenz.aboutlibraries.plugin", version.ref = "aboutLibraries" } +android-lint = { id = "com.android.lint", version.ref = "agp" } android-test = { id = "com.android.test", version.ref = "agp" } anvil = "com.squareup.anvil:2.5.0-beta03" baselineprofile = { id = "androidx.baselineprofile", version.ref = "benchmark" }