Skip to content

Commit 0d29bc3

Browse files
committed
Add and setup static analysis: Detekt.
1 parent 7ee6e76 commit 0d29bc3

File tree

5 files changed

+661
-2
lines changed

5 files changed

+661
-2
lines changed

README.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -55,6 +55,7 @@ Here are some useful Gradle/adb commands for executing this example:
5555
* `./gradlew runUnitTests` - Execute unit tests (both unit and integration).
5656
* `./gradlew runAcceptanceTests` - Execute acceptance and instrumentation tests in the connected device.
5757
* `./gradlew runTestCoverage` - Reports code coverage on tests within the Android codebase.
58+
* `./gradlew runStaticCodeAnalysis` - Run static analysis on the Android codebase.
5859

5960
## Discussions
6061
Refer to the issues section: https://github.com/android10/Android-CleanArchitecture-Kotlin/issues

app/src/test/kotlin/com/fernandocejas/sample/features/movies/MoviesRepositoryTest.kt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -122,7 +122,7 @@ class MoviesRepositoryTest : UnitTest() {
122122
val movieDetails = networkRepository.movieDetails(1)
123123

124124
movieDetails shouldEqual Right(MovieDetails.empty())
125-
verify(exactly = 1) {service.movieDetails(1) }
125+
verify(exactly = 1) { service.movieDetails(1) }
126126
}
127127

128128
@Test fun `should get movie details from service`() {

buildSrc/build.gradle.kts

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
object Dependencies {
22
const val AndroidBuildTools = "com.android.tools.build:gradle:4.0.1"
3+
const val detektGradlePlugin = "io.gitlab.arturbosch.detekt:detekt-gradle-plugin:1.14.1"
34
}
45

56
plugins {
@@ -14,4 +15,5 @@ repositories {
1415

1516
dependencies {
1617
implementation(Dependencies.AndroidBuildTools)
18+
implementation(Dependencies.detektGradlePlugin)
1719
}

buildSrc/src/main/kotlin/scripts/quality.gradle.kts

Lines changed: 28 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,12 @@
11
package scripts
22

3+
import io.gitlab.arturbosch.detekt.Detekt
34
import scripts.Variants_gradle.*
45

56
plugins {
67
id("com.android.application") apply false
78
id("jacoco")
9+
id("io.gitlab.arturbosch.detekt")
810
}
911

1012
android {
@@ -71,4 +73,29 @@ tasks.register("runTestCoverage") {
7173
group = "Quality"
7274
description = "Report code coverage on tests within the Android codebase."
7375
dependsOn("jacocoReport")
74-
}
76+
}
77+
78+
val detektAll by tasks.registering(Detekt::class) {
79+
group = "Quality"
80+
description = "Runs a detekt code analysis ruleset on the Android codebase."
81+
parallel = true
82+
buildUponDefaultConfig = true
83+
84+
setSource(files(rootProject.projectDir))
85+
config.setFrom(project.rootDir.resolve("config/detekt/detekt.yml"))
86+
87+
include("**/*.kt")
88+
exclude("**/*.kts", "*/build/*", "/buildSrc")
89+
90+
reports {
91+
xml.enabled = true
92+
html.enabled = true
93+
txt.enabled = false
94+
}
95+
}
96+
97+
tasks.register("runStaticCodeAnalysis") {
98+
description = "Run static analysis on the Android codebase."
99+
dependsOn(detektAll)
100+
}
101+

0 commit comments

Comments
 (0)