-
-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy pathbuild.gradle.kts
149 lines (134 loc) · 4.43 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
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
import io.gitlab.arturbosch.detekt.Detekt
import org.jetbrains.dokka.gradle.DokkaTaskPartial
plugins {
alias(libs.plugins.android.application) apply false
alias(libs.plugins.android.library) apply false
alias(libs.plugins.compose.compiler) version libs.versions.kotlin apply false
alias(libs.plugins.detekt) version libs.versions.detekt
alias(libs.plugins.dokka) version libs.versions.dokka
alias(libs.plugins.google.devtools.ksp) version libs.versions.kspVersion apply false
alias(libs.plugins.hilt.android) version libs.versions.hiltVersion apply false
jacoco
alias(libs.plugins.jetbrains.kotlin.android) apply false
alias(libs.plugins.google.gms.google.services) apply false
alias(libs.plugins.kotlin.serialization) apply false
alias(libs.plugins.kotlin.parcelize) apply false
}
subprojects {
setupDokka()
setupDetekt()
setupJacoco()
}
installCustomTasks()
tasks.dokkaHtmlMultiModule {
moduleName.set("Spezi Documentation")
}
fun Project.setupDokka() {
apply(plugin = rootProject.libs.plugins.dokka.get().pluginId)
if (this != rootProject) {
rootProject.tasks.named("dokkaHtmlMultiModule") {
dependsOn("${project.path}:dokkaHtml")
}
}
tasks.withType<DokkaTaskPartial>().configureEach {
dokkaSourceSets.configureEach {
noAndroidSdkLink.set(false)
skipDeprecated.set(true)
skipEmptyPackages.set(true)
includeNonPublic.set(false)
jdkVersion.set(JavaVersion.VERSION_17.majorVersion.toInt())
if (file("README.md").exists()) {
includes.from("README.md")
}
}
}
val dokkaHtmlMultiModule = tasks.findByName("dokkaHtmlMultiModule") ?: tasks.create(
"dokkaHtmlMultiModule",
DokkaTaskPartial::class.java
)
rootProject.tasks.named("dokkaHtmlMultiModule") {
dependsOn(dokkaHtmlMultiModule)
}
}
fun Project.setupDetekt() {
val libs = rootProject.libs
apply(plugin = libs.plugins.detekt.get().pluginId)
detekt {
toolVersion = libs.versions.detekt.get()
config.setFrom("$rootDir/internal/detekt-config.yml")
autoCorrect = true
ignoreFailures = false
source.setFrom(
files(
"src/main",
"src/test",
"src/androidTest",
"build.gradle.kts"
)
)
}
dependencies {
detektPlugins(libs.detekt.formatting)
}
tasks.withType<Detekt> {
jvmTarget = JavaVersion.VERSION_17.toString()
reports {
xml.required.set(true)
html.required.set(true)
txt.required.set(true)
sarif.required.set(true)
}
}
}
fun Project.setupJacoco() {
apply(plugin = "jacoco")
val buildDir = layout.buildDirectory.get()
val coverageExclusions = listOf(
// Android
"**/R.class",
"**/R\$*.class",
"**/BuildConfig.*",
"**/Manifest*.*",
"**/*_Hilt*.class",
"**/Hilt_*.class",
"**/*Activity.class",
"**/*Application.class",
"**/di/*Module.*",
)
val reportTask = tasks.register("jacocoCoverageReport", JacocoReport::class.java) {
classDirectories.setFrom(
fileTree("$buildDir/intermediates/classes/debug") {
exclude(coverageExclusions)
} + fileTree("$buildDir/tmp/kotlin-classes/debug") {
exclude(coverageExclusions)
}
)
reports {
html.required.set(true)
xml.required.set(true)
}
sourceDirectories.setFrom(files("$projectDir/src/main"))
executionData.setFrom(
files("$buildDir/outputs/unit_test_code_coverage/debugUnitTest/testDebugUnitTest.exec")
)
doLast {
println("Jacoco report generated in: ${reports.html.outputLocation.get()}")
}
}
tasks.withType<Test>().configureEach {
configure<JacocoTaskExtension> {
isIncludeNoLocationClasses = true
excludes = listOf("jdk.internal.*")
}
finalizedBy(reportTask)
}
}
/**
* Installs all custom tasks defined in /gradle/tasks
*/
fun Project.installCustomTasks() {
val tasksDir = File("$rootDir/gradle/tasks")
if (tasksDir.exists() && tasksDir.isDirectory) {
tasksDir.listFiles { file -> file.extension == "kts" }?.forEach { file -> apply(from = file) }
}
}