diff --git a/.idea/deploymentTargetDropDown.xml b/.idea/deploymentTargetDropDown.xml index 19d52d86..0c0c3383 100644 --- a/.idea/deploymentTargetDropDown.xml +++ b/.idea/deploymentTargetDropDown.xml @@ -1,17 +1,10 @@ - - - - - - - - - - - - + + + + + \ No newline at end of file diff --git a/.idea/gradle.xml b/.idea/gradle.xml index 606969d0..aa92f772 100644 --- a/.idea/gradle.xml +++ b/.idea/gradle.xml @@ -4,10 +4,8 @@ diff --git a/.idea/misc.xml b/.idea/misc.xml index 773fe0fb..8978d23d 100644 --- a/.idea/misc.xml +++ b/.idea/misc.xml @@ -1,6 +1,6 @@ - + diff --git a/app/build.gradle.kts b/app/build.gradle.kts index 67187bf0..7fafdfdc 100644 --- a/app/build.gradle.kts +++ b/app/build.gradle.kts @@ -3,6 +3,7 @@ plugins { id(Plugins.Core) id(Plugins.Ksp) id(Plugins.ComposeCore) + id("detekt-plugin") } android { diff --git a/build.gradle.kts b/build.gradle.kts index 00c362df..d62e9a86 100644 --- a/build.gradle.kts +++ b/build.gradle.kts @@ -15,6 +15,7 @@ buildscript { plugins { id(Plugins.Ksp) version Versions.Compose.KspPlugin apply false + id(Plugins.Detekt) version Versions.Detekt } allprojects { diff --git a/buildSrc/build.gradle.kts b/buildSrc/build.gradle.kts index dacdb2d6..a7d79468 100644 --- a/buildSrc/build.gradle.kts +++ b/buildSrc/build.gradle.kts @@ -11,6 +11,7 @@ repositories { dependencies { implementation("com.android.tools.build:gradle:7.4.0") implementation(kotlin("gradle-plugin", "1.8.10")) + compileOnly("io.gitlab.arturbosch.detekt:detekt-gradle-plugin:1.21.0") } gradlePlugin { @@ -21,7 +22,8 @@ gradlePlugin { "compose-core-plugin" to "plugin.compose.ComposeCorePlugin", "compose-feature-plugin" to "plugin.compose.ComposeFeaturePlugin", "room-db-plugin" to "plugin.RoomPlugin", - "ut-plugin" to "plugin.UnitTestPlugin" + "ut-plugin" to "plugin.UnitTestPlugin", + "detekt-plugin" to "plugin.DetektConventionPlugin" ) plugins.forEach { diff --git a/buildSrc/src/main/java/Dependencies.kt b/buildSrc/src/main/java/Dependencies.kt index 8ed9804b..fd52e7b2 100644 --- a/buildSrc/src/main/java/Dependencies.kt +++ b/buildSrc/src/main/java/Dependencies.kt @@ -5,6 +5,11 @@ object Dependencies { const val ProfilerInstaller = "androidx.profileinstaller:profileinstaller:1.3.0" const val Benchmark = "androidx.benchmark:benchmark-macro-junit4:1.2.0-alpha13" + object DeteKt { + const val Compose = "o.nlopez.compose.rules:detekt:0.3.0" + const val Gradle = "io.gitlab.arturbosch.detekt:detekt-gradle-plugin:${Versions.Detekt}" + } + object AndroidX { const val Glance = "androidx.glance:glance:1.0.0-alpha05" const val GlanceAppWidget = "androidx.glance:glance-appwidget:1.0.0-alpha05" diff --git a/buildSrc/src/main/java/Plugins.kt b/buildSrc/src/main/java/Plugins.kt index df2e4ef8..b7e7cd44 100644 --- a/buildSrc/src/main/java/Plugins.kt +++ b/buildSrc/src/main/java/Plugins.kt @@ -38,4 +38,5 @@ object Plugins { const val AndroidLibrary = "com.android.library" const val AndroidApplication = "com.android.application" const val Ksp = "com.google.devtools.ksp" + const val Detekt = "io.gitlab.arturbosch.detekt" } \ No newline at end of file diff --git a/buildSrc/src/main/java/Versions.kt b/buildSrc/src/main/java/Versions.kt index eadd8de3..61c41769 100644 --- a/buildSrc/src/main/java/Versions.kt +++ b/buildSrc/src/main/java/Versions.kt @@ -2,6 +2,7 @@ object Versions { const val Kotlin = "1.8.10" const val Coroutine = "1.6.4" const val Room = "2.4.2" + const val Detekt = "1.21.0" object Compose { const val OrbitMvi = "4.5.0" diff --git a/buildSrc/src/main/java/plugin/DetektConventionPlugin.kt b/buildSrc/src/main/java/plugin/DetektConventionPlugin.kt new file mode 100644 index 00000000..4d1e7414 --- /dev/null +++ b/buildSrc/src/main/java/plugin/DetektConventionPlugin.kt @@ -0,0 +1,58 @@ +package plugin + +import Dependencies +import Plugins +import io.gitlab.arturbosch.detekt.extensions.DetektExtension +import org.gradle.api.JavaVersion +import org.gradle.api.Plugin +import org.gradle.api.Project +import org.gradle.kotlin.dsl.getByType +import org.gradle.kotlin.dsl.withType + +class DetektConventionPlugin : Plugin { + override fun apply(project: Project) { + with(project) { + // Apply detekt plugin to module + pluginManager.apply(Plugins.Detekt) + + // Configure jvmTarget for gradle task `detekt` + tasks.withType().configureEach { + jvmTarget = JavaVersion.VERSION_17.toString() + } + // Configure jvmTarget for gradle task `detektGenerateBaseline` + tasks.withType().configureEach { + jvmTarget = JavaVersion.VERSION_17.toString() + } + + // Configure detekt + extensions.getByType().apply { + buildUponDefaultConfig = true // preconfigure defaults. + allRules = false // activate all available (even unstable) rules. + autoCorrect = false // To enable or disable auto formatting. + parallel = true // To enable or disable parallel execution of detekt on multiple submodules. + config.setFrom("config/detekt/detekt.yml") // point to your custom config defining rules to run, overwriting default behavior. + baseline = + file("config/detekt/detekt-baseline.xml") // a way of suppressing issues before introducing detekt. + } + + tasks.withType().configureEach { + reports { + // observe findings in your browser with structure and code snippets + html.required.set(true) + // similar to the console output, contains issue signature to manually edit baseline files + txt.required.set(true) + // simple Markdown format + md.required.set(true) + } + } + + dependencies.apply { + // You can add more detektPlugins like shown below. + add( + "detektPlugins", + Dependencies.DeteKt.Compose + ) // Add this in case you want compose rules with detekt + } + } + } +} diff --git a/buildSrc/src/main/java/plugin/base/CorePlugin.kt b/buildSrc/src/main/java/plugin/base/CorePlugin.kt index d48e6031..30e7b9cc 100644 --- a/buildSrc/src/main/java/plugin/base/CorePlugin.kt +++ b/buildSrc/src/main/java/plugin/base/CorePlugin.kt @@ -10,7 +10,6 @@ import org.gradle.kotlin.dsl.dependencies import org.jetbrains.kotlin.gradle.tasks.KotlinCompile import plugin.util.PluginConstants import plugin.util.implementation -import java.io.File /** * Plugin containing all common code for any gradle @@ -24,6 +23,7 @@ open class CorePlugin : Plugin { apply("kotlinx-serialization") apply("kotlin-parcelize") apply("org.sonarqube") +// apply("detekt-plugin") } val androidExtension =