Skip to content

Commit

Permalink
detekt setup
Browse files Browse the repository at this point in the history
  • Loading branch information
pseudoankit committed Nov 23, 2023
1 parent b003b5b commit 8943e51
Show file tree
Hide file tree
Showing 11 changed files with 79 additions and 18 deletions.
17 changes: 5 additions & 12 deletions .idea/deploymentTargetDropDown.xml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

5 changes: 2 additions & 3 deletions .idea/gradle.xml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion .idea/misc.xml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

1 change: 1 addition & 0 deletions app/build.gradle.kts
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ plugins {
id(Plugins.Core)
id(Plugins.Ksp)
id(Plugins.ComposeCore)
id("detekt-plugin")
}

android {
Expand Down
1 change: 1 addition & 0 deletions build.gradle.kts
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@ buildscript {

plugins {
id(Plugins.Ksp) version Versions.Compose.KspPlugin apply false
id(Plugins.Detekt) version Versions.Detekt
}

allprojects {
Expand Down
4 changes: 3 additions & 1 deletion buildSrc/build.gradle.kts
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand All @@ -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 {
Expand Down
5 changes: 5 additions & 0 deletions buildSrc/src/main/java/Dependencies.kt
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand Down
1 change: 1 addition & 0 deletions buildSrc/src/main/java/Plugins.kt
Original file line number Diff line number Diff line change
Expand Up @@ -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"
}
1 change: 1 addition & 0 deletions buildSrc/src/main/java/Versions.kt
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand Down
58 changes: 58 additions & 0 deletions buildSrc/src/main/java/plugin/DetektConventionPlugin.kt
Original file line number Diff line number Diff line change
@@ -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<Project> {
override fun apply(project: Project) {
with(project) {
// Apply detekt plugin to module
pluginManager.apply(Plugins.Detekt)

// Configure jvmTarget for gradle task `detekt`
tasks.withType<io.gitlab.arturbosch.detekt.Detekt>().configureEach {
jvmTarget = JavaVersion.VERSION_17.toString()
}
// Configure jvmTarget for gradle task `detektGenerateBaseline`
tasks.withType<io.gitlab.arturbosch.detekt.DetektCreateBaselineTask>().configureEach {
jvmTarget = JavaVersion.VERSION_17.toString()
}

// Configure detekt
extensions.getByType<DetektExtension>().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<io.gitlab.arturbosch.detekt.Detekt>().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
}
}
}
}
2 changes: 1 addition & 1 deletion buildSrc/src/main/java/plugin/base/CorePlugin.kt
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -24,6 +23,7 @@ open class CorePlugin : Plugin<Project> {
apply("kotlinx-serialization")
apply("kotlin-parcelize")
apply("org.sonarqube")
// apply("detekt-plugin")
}

val androidExtension =
Expand Down

0 comments on commit 8943e51

Please sign in to comment.