-
Notifications
You must be signed in to change notification settings - Fork 0
/
build.gradle.kts
173 lines (141 loc) · 5.39 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
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.gradle.api.tasks.testing.logging.TestExceptionFormat
import org.gradle.api.tasks.testing.logging.TestLogEvent
import org.jetbrains.dokka.gradle.DokkaTaskPartial
import com.diffplug.gradle.spotless.SpotlessExtension
import org.jetbrains.dokka.gradle.DokkaMultiModuleTask
import org.jetbrains.kotlin.gradle.tasks.KotlinCompile
plugins {
kotlin(Libs.Plugins.kotlinJVM) version Libs.Versions.kotlin
id(Libs.Plugins.dokka) version (Libs.Versions.dokka)
id(Libs.Plugins.spotless) version Libs.Versions.spotless
id(Libs.Plugins.detekt) version Libs.Versions.detekt
}
buildscript {
repositories {
gradlePluginPortal()
google()
mavenCentral()
}
dependencies {
classpath(Libs.androidGradlePlugin)
classpath(Libs.Kotlin.gradlePlugin)
classpath(Libs.AndroidX.Navigation.navigationPlugin)
classpath(Libs.DaggerHilt.classPath)
classpath(Libs.TestDependencies.Junit5.classPath)
classpath(Libs.dependencyUpdates)
}
}
subprojects {
plugins.apply(Libs.Plugins.updateVersions)
plugins.apply(Libs.Plugins.detekt)
plugins.apply(Libs.Plugins.dokka)
plugins.apply(Libs.Plugins.spotless)
configure<SpotlessExtension> {
kotlin {
target("**/*.kt")
targetExclude("$buildDir/**/*.kt")
targetExclude("bin/**/*.kt")
ktlint(Libs.Versions.ktlint)
licenseHeaderFile("${project.rootProject.projectDir}/config/spotless/copyright.kt")
}
kotlinGradle {
target("*.gradle.kts")
ktlint()
}
}
tasks.named<DokkaTaskPartial>("dokkaHtmlPartial") {
dokkaSourceSets.configureEach {
noAndroidSdkLink.set(true)
suppressInheritedMembers.set(true)
}
}
detekt {
config = rootProject.files("$rootDir/config/detekt/detekt.yml")
reports {
html {
enabled = true
destination = file("$rootDir/reports/detekt/detekt.html")
}
}
}
dependencies {
detektPlugins(Libs.detekt)
}
}
/*Document Generation for all modules*/
tasks.withType<DokkaMultiModuleTask>().configureEach {
outputDirectory.set(file("$rootDir/reports/dokka"))
}
/*
Generate dependency graph for app in terms of modules
* */
apply(from = file("$rootDir/gradle/dependencyGraph.gradle"))
/*
Generate dependency graph for app in terms of dependency
* */
project.rootProject.allprojects {
apply(plugin = "project-report")
this.task("allDependencies", DependencyReportTask::class) {
outputFile = file("$rootDir/reports/dependencies.txt")
evaluationDependsOnChildren()
this.setRenderer(org.gradle.api.tasks.diagnostics.internal.dependencies.AsciiDependencyReportRenderer())
}
}
/*
Junit5 Configuration for all modules
* */
subprojects {
tasks.withType<Test> {
useJUnitPlatform()
testLogging {
lifecycle {
events =
mutableSetOf(TestLogEvent.FAILED, TestLogEvent.PASSED, TestLogEvent.SKIPPED)
exceptionFormat = TestExceptionFormat.FULL
showExceptions = true
showCauses = true
showStackTraces = true
showStandardStreams = true
}
info.events = lifecycle.events
info.exceptionFormat = lifecycle.exceptionFormat
}
val failedTests = mutableListOf<TestDescriptor>()
val skippedTests = mutableListOf<TestDescriptor>()
// See https://github.com/gradle/kotlin-dsl/issues/836
addTestListener(object : TestListener {
override fun beforeSuite(suite: TestDescriptor) {}
override fun beforeTest(testDescriptor: TestDescriptor) {}
override fun afterTest(testDescriptor: TestDescriptor, result: TestResult) {
when (result.resultType) {
TestResult.ResultType.FAILURE -> failedTests.add(testDescriptor)
TestResult.ResultType.SKIPPED -> skippedTests.add(testDescriptor)
else -> Unit
}
}
override fun afterSuite(suite: TestDescriptor, result: TestResult) {
if (suite.parent == null) { // root suite
logger.lifecycle("----")
logger.lifecycle("Test result: ${result.resultType}")
logger.lifecycle(
"Test summary: ${result.testCount} tests, " +
"${result.successfulTestCount} succeeded, " +
"${result.failedTestCount} failed, " +
"${result.skippedTestCount} skipped"
)
failedTests.takeIf { it.isNotEmpty() }?.prefixedSummary("\tFailed Tests")
skippedTests.takeIf { it.isNotEmpty() }?.prefixedSummary("\tSkipped Tests:")
}
}
private infix fun List<TestDescriptor>.prefixedSummary(subject: String) {
logger.lifecycle(subject)
forEach { test -> logger.lifecycle("\t\t${test.displayName()}") }
}
private fun TestDescriptor.displayName() =
parent?.let { "${it.name} - $name" } ?: "$name"
})
}
}
tasks.withType<KotlinCompile>().configureEach {
kotlinOptions.freeCompilerArgs += "-Xopt-in=Kotlin.RequiresOptIn"
}