-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathbuild.gradle.kts
More file actions
173 lines (160 loc) · 5.67 KB
/
build.gradle.kts
File metadata and controls
173 lines (160 loc) · 5.67 KB
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
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
import org.apache.tools.ant.taskdefs.condition.Os
/*
* By listing all the plugins used throughout all subprojects in the root project build script, it
* ensures that the build script classpath remains the same for all projects. This avoids potential
* problems with mismatching versions of transitive plugin dependencies. A subproject that applies
* an unlisted plugin will have that plugin and its dependencies _appended_ to the classpath, not
* replacing pre-existing dependencies.
*/
plugins {
alias(libs.plugins.android.application) apply false
alias(libs.plugins.kotlin.android) apply false
alias(libs.plugins.kotlin.compose) apply false
alias(libs.plugins.kotliner) apply false
alias(libs.plugins.roborazzi) apply false
alias(libs.plugins.dependencyGuard) apply false
alias(libs.plugins.square.sort.dependencies) apply false
alias(libs.plugins.detekt) apply true
alias(libs.plugins.ksp) apply false
}
tasks.register("clean", Delete::class) {
delete(rootProject.layout.buildDirectory)
}
configureGitHooks()
fun Project.configureGitHooks() {
registerCopyCommitMsgHookTask()
registerCopyPreCommitHookTask()
registerCopyPrePushHookTask()
registerCopyGitHooksTask()
registerInstallGitHooksTask()
}
fun Project.registerCopyPreCommitHookTask() {
tasks.register("copyPreCommitHook", Copy::class.java) {
group = "git hooks"
val suffix = osSuffix()
val preCommitFile = file("$rootDir/.git/hooks/pre-commit")
doFirst {
if (preCommitFile.exists()) {
logger.warn("\u001b[31mExisting pre-commit hook found. Deleting...\u001b[0m")
if (!preCommitFile.delete()) {
throw GradleException("Failed to delete existing pre-commit hook. Please check file permissions.")
}
}
}
from(file("$rootDir/git-hooks/pre-commit-$suffix.sh"))
into("$rootDir/.git/hooks")
rename("pre-commit-$suffix.sh", "pre-commit")
filePermissions {
user {
read = true
write = true
execute = true
}
}
}
}
fun Project.registerCopyPrePushHookTask() {
tasks.register("copyPrePushHook", Copy::class.java) {
group = "git hooks"
val suffix = osSuffix()
val prePushFile = file("$rootDir/.git/hooks/pre-push")
doFirst {
if (prePushFile.exists()) {
logger.warn("\u001b[31mExisting pre-push hook found. Deleting...\u001b[0m")
if (!prePushFile.delete()) {
throw GradleException("Failed to delete existing pre-push hook. Please check file permissions.")
}
}
}
from(file("$rootDir/git-hooks/pre-push-$suffix.sh"))
into("$rootDir/.git/hooks")
rename("pre-push-$suffix.sh", "pre-push")
filePermissions {
user {
read = true
write = true
execute = true
}
}
}
}
fun Project.registerCopyCommitMsgHookTask() {
tasks.register("copyCommitMsgHook", Copy::class.java) {
group = "git hooks"
val suffix = osSuffix()
val commitMsgFile = file("$rootDir/.git/hooks/commit-msg")
doFirst {
if (commitMsgFile.exists()) {
logger.warn("\u001b[31mExisting commit-msg hook found. Deleting...\u001b[0m")
if (!commitMsgFile.delete()) {
throw GradleException("Failed to delete existing commit-msg hook. Please check file permissions.")
}
}
}
from(file("$rootDir/git-hooks/commit-msg-$suffix.sh"))
into("$rootDir/.git/hooks")
rename("commit-msg-$suffix.sh", "commit-msg")
filePermissions {
user {
read = true
write = true
execute = true
}
}
}
}
fun Project.registerCopyGitHooksTask() {
tasks.register("copyGitHooks", Copy::class.java) {
group = "git hooks"
description = "Copies the git hooks from /git-hooks to the .git folder."
dependsOn("copyPrePushHook", "copyPreCommitHook", "copyCommitMsgHook")
}
}
fun Project.registerInstallGitHooksTask() {
tasks.register("installGitHooks", Exec::class.java) {
group = "git hooks"
description = "Installs the pre-commit git hooks from /git-hooks."
workingDir = rootDir
if (Os.isFamily(Os.FAMILY_WINDOWS)) {
commandLine("attrib", "+r", "/s", ".git\\hooks\\*.*")
} else {
commandLine("chmod", "-R", "+x", ".git/hooks/")
}
dependsOn("copyGitHooks")
doLast {
logger.info("Git hook installed successfully.")
}
}
}
fun osSuffix(): String {
return if (Os.isFamily(Os.FAMILY_WINDOWS)) {
"windows"
} else {
"unix"
}
}
afterEvaluate {
// We install the hook at the first occasion
tasks.named("clean") {
dependsOn(":installGitHooks")
}
}
tasks {
/**
* The detektAll tasks enables parallel usage for detekt so if this project
* expands to multi module support, detekt can continue to run quickly.
*
* https://proandroiddev.com/how-to-use-detekt-in-a-multi-module-android-project-6781937fbef2
*/
@Suppress("UnusedPrivateMember")
val detektAll by registering(io.gitlab.arturbosch.detekt.Detekt::class) {
parallel = true
setSource(files(projectDir))
include("**/*.kt")
include("**/*.kts")
exclude("**/resources/**")
exclude("**/build/**")
config.setFrom(files("$rootDir/config/detekt/detekt.yml"))
buildUponDefaultConfig = true
}
}