From 839773e48e1de97eab004c178772a7a4a104f97c Mon Sep 17 00:00:00 2001 From: Harsh Shandilya Date: Mon, 14 Nov 2022 13:56:56 +0530 Subject: [PATCH] refactor(gradle): configure Lint for all modules --- android/build.gradle.kts | 7 ------- api/lint-baseline.xml | 4 ++++ .../aps/gradle/AndroidCommonPlugin.kt | 19 +++++++++++++++++-- common/lint-baseline.xml | 4 ++++ core/lint-baseline.xml | 4 ++++ database/lint-baseline.xml | 4 ++++ 6 files changed, 33 insertions(+), 9 deletions(-) create mode 100644 api/lint-baseline.xml create mode 100644 common/lint-baseline.xml create mode 100644 core/lint-baseline.xml create mode 100644 database/lint-baseline.xml diff --git a/android/build.gradle.kts b/android/build.gradle.kts index 2f132a82..01c14d51 100644 --- a/android/build.gradle.kts +++ b/android/build.gradle.kts @@ -38,13 +38,6 @@ android { isDebuggable = false } } - lint { - abortOnError = false - checkReleaseBuilds = false - warningsAsErrors = false - disable.add("DialogFragmentCallbacksDetector") - baseline = file("lint-baseline.xml") - } } dependencies { diff --git a/api/lint-baseline.xml b/api/lint-baseline.xml new file mode 100644 index 00000000..4c140d8c --- /dev/null +++ b/api/lint-baseline.xml @@ -0,0 +1,4 @@ + + + + diff --git a/build-logic/android-plugins/src/main/kotlin/dev/msfjarvis/aps/gradle/AndroidCommonPlugin.kt b/build-logic/android-plugins/src/main/kotlin/dev/msfjarvis/aps/gradle/AndroidCommonPlugin.kt index 1ae8f4c8..f49b5fdf 100644 --- a/build-logic/android-plugins/src/main/kotlin/dev/msfjarvis/aps/gradle/AndroidCommonPlugin.kt +++ b/build-logic/android-plugins/src/main/kotlin/dev/msfjarvis/aps/gradle/AndroidCommonPlugin.kt @@ -4,12 +4,17 @@ * license that can be found in the LICENSE file or at * https://opensource.org/licenses/MIT. */ +@file:Suppress("UnstableApiUsage") + package dev.msfjarvis.aps.gradle +import com.android.build.api.dsl.LibraryExtension +import com.android.build.api.dsl.Lint import com.android.build.api.dsl.TestExtension import com.android.build.api.variant.ApplicationAndroidComponentsExtension import com.android.build.api.variant.LibraryAndroidComponentsExtension import com.android.build.gradle.TestedExtension +import com.android.build.gradle.internal.dsl.BaseAppModuleExtension import org.gradle.android.AndroidCacheFixPlugin import org.gradle.api.JavaVersion import org.gradle.api.Plugin @@ -19,7 +24,6 @@ import org.gradle.kotlin.dsl.findByType private const val SLIM_TESTS_PROPERTY = "slimTests" -@Suppress("UnstableApiUsage") class AndroidCommonPlugin : Plugin { private companion object { @@ -27,9 +31,12 @@ class AndroidCommonPlugin : Plugin { const val MIN_SDK = 26 const val TARGET_SDK = 33 } + override fun apply(project: Project) { project.configureSlimTests() project.pluginManager.apply(AndroidCacheFixPlugin::class) + project.extensions.findByType()?.run { lint.configureLint(project) } + project.extensions.findByType()?.run { lint.configureLint(project) } project.extensions.findByType()?.run { compileSdkVersion(COMPILE_SDK) defaultConfig { @@ -81,6 +88,14 @@ class AndroidCommonPlugin : Plugin { } } +private fun Lint.configureLint(project: Project) { + abortOnError = false + checkReleaseBuilds = false + warningsAsErrors = false + disable.add("DialogFragmentCallbacksDetector") + baseline = project.file("lint-baseline.xml") +} + /** * When the "slimTests" project property is provided, disable the unit test tasks on `release` build * type and `nonFree` product flavor to avoid running the same tests repeatedly in different build @@ -89,7 +104,7 @@ class AndroidCommonPlugin : Plugin { * Examples: `./gradlew test -PslimTests` will run unit tests for `nonFreeDebug` and `debug` build * variants in Android App and Library projects, and all tests in JVM projects. */ -internal fun Project.configureSlimTests() { +private fun Project.configureSlimTests() { if (providers.gradleProperty(SLIM_TESTS_PROPERTY).isPresent) { // Disable unit test tasks on the release build type for Android Library projects extensions.findByType()?.run { diff --git a/common/lint-baseline.xml b/common/lint-baseline.xml new file mode 100644 index 00000000..4c140d8c --- /dev/null +++ b/common/lint-baseline.xml @@ -0,0 +1,4 @@ + + + + diff --git a/core/lint-baseline.xml b/core/lint-baseline.xml new file mode 100644 index 00000000..4c140d8c --- /dev/null +++ b/core/lint-baseline.xml @@ -0,0 +1,4 @@ + + + + diff --git a/database/lint-baseline.xml b/database/lint-baseline.xml new file mode 100644 index 00000000..4c140d8c --- /dev/null +++ b/database/lint-baseline.xml @@ -0,0 +1,4 @@ + + + +