-
Notifications
You must be signed in to change notification settings - Fork 0
/
build.gradle.kts
186 lines (157 loc) · 6.3 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
174
175
176
177
178
179
180
181
182
183
184
185
186
import app.template.buildsrc.AppDependencyUpdates
import app.template.buildsrc.ReleaseType
import com.diffplug.gradle.spotless.SpotlessExtension
import com.github.benmanes.gradle.versions.updates.DependencyUpdatesTask
import org.gradle.api.tasks.testing.logging.TestExceptionFormat
import org.gradle.api.tasks.testing.logging.TestLogEvent
import org.jetbrains.dokka.gradle.DokkaMultiModuleTask
import org.jetbrains.dokka.gradle.DokkaTaskPartial
import org.jetbrains.kotlin.gradle.tasks.KotlinCompile
plugins {
alias(libs.plugins.dokka)
alias(libs.plugins.detekt)
alias(libs.plugins.spotless)
alias(libs.plugins.gradleDependencyUpdate)
}
buildscript {
repositories {
google()
mavenCentral()
}
dependencies {
classpath(libs.android.pluginGradle)
classpath(libs.kotlin.pluginGradle)
classpath(libs.hilt.pluginGradle)
classpath(libs.junit5.pluginGradle)
classpath(libs.androidx.navigation.safeArgument)
classpath(libs.google.crashlyticsGradle)
classpath(libs.google.gmsGoogleServices)
}
}
subprojects {
plugins.apply("io.gitlab.arturbosch.detekt")
plugins.apply("org.jetbrains.dokka")
plugins.apply("com.diffplug.spotless")
configure<SpotlessExtension> {
kotlin {
target("**/*.kt")
targetExclude("$buildDir/**/*.kt")
targetExclude("bin/**/*.kt")
ktlint(libs.versions.ktlint.get())
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 {
description = "Runs over whole code base without the starting overhead for each module."
parallel = true
buildUponDefaultConfig = true
autoCorrect = true
config.setFrom(files("${rootProject.rootDir}/config/detekt/detekt.yml"))
reports {
html.required.set(true)
html.outputLocation.set(file("${rootProject.rootDir}/reports/detekt/detekt.html"))
}
}
dependencies {
detektPlugins("io.gitlab.arturbosch.detekt:detekt-formatting:1.19.0")
}
}
/*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"))
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())
}
}
//Task added to know the updated depencecy
tasks.withType<DependencyUpdatesTask> {
rejectVersionIf {
val current = AppDependencyUpdates.versionToRelease(currentVersion)
// If we're using a SNAPSHOT, ignore since we must be doing so for a reason.
if (current == ReleaseType.SNAPSHOT) return@rejectVersionIf true
// Otherwise we reject if the candidate is more 'unstable' than our version
val candidate = AppDependencyUpdates.versionToRelease(candidate.version)
return@rejectVersionIf candidate.isLessStableThan(current)
}
checkForGradleUpdate = true
outputFormatter = "json"
outputDir = "$rootDir/reports/dependencyUpdates"
reportfileName = "report"
}
/*
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"
}