-
Notifications
You must be signed in to change notification settings - Fork 0
/
build.gradle.kts
97 lines (84 loc) · 3.18 KB
/
build.gradle.kts
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
@Suppress("DSL_SCOPE_VIOLATION")
plugins {
alias(libs.plugins.android.application) apply false
alias(libs.plugins.android.library) apply false
alias(libs.plugins.kotlin.android) apply false
alias(libs.plugins.hilt.android) apply false
alias(libs.plugins.ksp) apply false
alias(libs.plugins.detekt)
alias(libs.plugins.kover) apply false
alias(libs.plugins.gms) apply false
alias(libs.plugins.firebase.appdistribution) apply false
}
// Workaround for "Expecting an expression" build error
println("")
val reportMerge by tasks.registering(io.gitlab.arturbosch.detekt.report.ReportMergeTask::class) {
output.set(rootProject.layout.buildDirectory.file("reports/detekt/merge.xml")) // or "reports/detekt/merge.sarif"
}
subprojects {
apply {
plugin("io.gitlab.arturbosch.detekt")
}
detekt {
toolVersion = "1.23.0"
config.from(rootProject.files("config/detekt/detekt.yml"))
baseline = file("${rootProject.projectDir}/config/detekt/baseline.xml")
autoCorrect = true
// The directories where detekt looks for source files.
// Defaults to `files("src/main/java", "src/test/java", "src/main/kotlin", "src/test/kotlin")`.
source.setFrom("src/main/java", "src/main/kotlin")
}
tasks.withType<io.gitlab.arturbosch.detekt.Detekt>().configureEach {
finalizedBy(reportMerge)
}
reportMerge {
input.from(tasks.withType<io.gitlab.arturbosch.detekt.Detekt>().map { it.xmlReportFile }) // or .sarifReportFile
}
tasks.withType<io.gitlab.arturbosch.detekt.Detekt>().configureEach {
reports {
xml.required.set(true)
html.required.set(true)
txt.required.set(true)
sarif.required.set(true)
md.required.set(true)
}
}
tasks.register("copyGitPreCommitHook", Copy::class.java) {
description = "Copies the git pre-commit.sh.sh hook from $detektPreCommitScript to the .git folder."
group = "Git Hooks"
from(detektPreCommitScript) {
include("**/*.sh")
rename("(.*).sh", "$1")
duplicatesStrategy = DuplicatesStrategy.EXCLUDE
}
into("$rootDir/.git/hooks")
onlyIf {
isLinuxOrMacOs()
}
}
tasks.register("installGitHooks", Exec::class.java) {
description = "Installs the pre-commit.sh.sh git hooks from $detektPreCommitScript."
group = "Git Hooks"
workingDir(rootDir)
commandLine("chmod")
args("-R", "+x", ".git/hooks")
dependsOn("copyGitPreCommitHook")
onlyIf {
isLinuxOrMacOs()
}
doLast {
println("Git hook installed successfully.")
}
}
tasks.getByPath("$path:assembleDebug").dependsOn("installGitHooks")
dependencies {
detektPlugins(libs.detekt.formatting)
detektPlugins(libs.detekt.twitter.compose)
}
}
fun isLinuxOrMacOs(): Boolean {
val osName = System.getProperty("os.name").lowercase(java.util.Locale.ROOT)
return osName.contains("linux") || osName.contains("mac os") || osName.contains("macos")
}
val detektPreCommitScript: String
get() = "$rootDir/scripts/pre-commit.sh"