Skip to content

Commit

Permalink
[#10] Detekt Integration and fixing existing errors (#39)
Browse files Browse the repository at this point in the history
  • Loading branch information
mustafaozhan authored Nov 10, 2023
1 parent 0b030c9 commit 407df03
Show file tree
Hide file tree
Showing 11 changed files with 44 additions and 5 deletions.
34 changes: 34 additions & 0 deletions build.gradle.kts
Original file line number Diff line number Diff line change
@@ -1,9 +1,12 @@
import io.gitlab.arturbosch.detekt.Detekt

plugins {
libs.plugins.apply {
alias(jetbrainsCompose) apply false
alias(androidApplication) apply false
alias(kotlinMultiplatform) apply false
alias(kover)
alias(detekt)
}
}

Expand All @@ -30,6 +33,37 @@ allprojects {
}
}

apply(plugin = rootProject.libs.plugins.detekt.get().pluginId).also {
detekt {
buildUponDefaultConfig = true
allRules = true
parallel = true
config.from("${rootProject.projectDir}/detekt.yml")
}
tasks.withType<Detekt> {
setSource(files(project.projectDir))
exclude("**/build/**")
exclude {
it.file.relativeTo(projectDir).startsWith(
project.layout.buildDirectory.asFile.get().relativeTo(projectDir)
)
}
}.onEach { detekt ->
// skip detekt tasks unless a it is specifically called
detekt.onlyIf {
gradle.startParameter.taskNames.any { it.contains("detekt") }
}
}

tasks.register("detektAll") {
dependsOn(tasks.withType<Detekt>())
}

dependencies {
detektPlugins(rootProject.libs.common.detektFormatting)
}
}

// todo CMP bug needs to be removed when fixed
// https://youtrack.jetbrains.com/issue/KT-41821/Kotlin-1.4.10-ios-target-java.lang.IllegalStateException-failed-to-resolve-Kotlin-library-org.jetbrains.kotlinx-atomicfu-common
apply(plugin = rootProject.libs.plugins.atomicfu.get().pluginId)
Expand Down
2 changes: 1 addition & 1 deletion composeApp/build.gradle.kts
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,7 @@ kotlin {
}
}

@Suppress("UnusedPrivateProperty")
sourceSets {
val androidMain by getting {
dependencies {
Expand Down Expand Up @@ -97,4 +98,3 @@ android {
debugImplementation(libs.android.composeUiTooling)
}
}

Original file line number Diff line number Diff line change
Expand Up @@ -21,4 +21,4 @@ class MainActivity : ComponentActivity() {
@Composable
fun AppAndroidPreview() {
App()
}
}
2 changes: 1 addition & 1 deletion composeApp/src/commonMain/kotlin/App.kt
Original file line number Diff line number Diff line change
Expand Up @@ -36,4 +36,4 @@ fun App() {
}
}
}
}
}
File renamed without changes.
2 changes: 1 addition & 1 deletion composeApp/src/commonMain/kotlin/Shared.kt
Original file line number Diff line number Diff line change
@@ -1 +1 @@
val GREETING = "Hello World!"
const val GREETING = "Hello World!"
File renamed without changes.
1 change: 1 addition & 0 deletions composeApp/src/iosMain/kotlin/MainViewController.kt
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
import androidx.compose.ui.window.ComposeUIViewController

@Suppress("unused", "FunctionNaming") // used in iOS
fun MainViewController() = ComposeUIViewController { App() }
3 changes: 3 additions & 0 deletions gradle/libs.versions.toml
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
[versions]
kotlin = "1.9.10"
atomicfu = "0.17.3"
detekt = "1.23.3"
kover = "0.6.1"
compose = "1.5.4"
jetbrainsCompose = "1.5.3"
Expand All @@ -12,6 +13,7 @@ androidx-activityCompose = "1.8.0"
# COMMON
kotlin-test = { module = "org.jetbrains.kotlin:kotlin-test", version.ref = "kotlin" }
common-ComposeCompiler = { module = "androidx.compose.compiler:compiler", version.ref = "composeCompiler" } # Workaround for compose compiler update
common-detektFormatting = { module = "io.gitlab.arturbosch.detekt:detekt-formatting", version.ref = "detekt" }

# ANDROID
android-activityCompose = { module = "androidx.activity:activity-compose", version.ref = "androidx-activityCompose" }
Expand All @@ -28,3 +30,4 @@ androidApplication = { id = "com.android.application", version.ref = "androidGra
kotlinMultiplatform = { id = "org.jetbrains.kotlin.multiplatform", version.ref = "kotlin" }
atomicfu = { id = "kotlinx-atomicfu" }
kover = { id = "org.jetbrains.kotlinx.kover", version.ref = "kover" }
detekt = { id = "io.gitlab.arturbosch.detekt", version.ref = "detekt" }
3 changes: 2 additions & 1 deletion settings.gradle.kts
Original file line number Diff line number Diff line change
Expand Up @@ -11,11 +11,12 @@ pluginManagement {
}

dependencyResolutionManagement {
@Suppress("UnstableApiUsage")
repositories {
google()
mavenCentral()
maven("https://maven.pkg.jetbrains.space/public/p/compose/dev")
}
}

include(":composeApp")
include(":composeApp")

0 comments on commit 407df03

Please sign in to comment.