-
Notifications
You must be signed in to change notification settings - Fork 0
/
build.gradle.kts
157 lines (137 loc) · 4.5 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
import java.util.EnumSet
import org.gradle.api.tasks.testing.logging.TestExceptionFormat
import org.gradle.api.tasks.testing.logging.TestLogEvent
import org.jetbrains.kotlin.gradle.dsl.JvmTarget
import org.jetbrains.kotlin.gradle.tasks.KotlinCompilationTask
import org.jetbrains.kotlin.gradle.tasks.KotlinCompile
plugins {
// trick: for the same plugin versions in all sub-modules
alias(libs.plugins.androidApplication).apply(false)
alias(libs.plugins.androidLibrary).apply(false)
alias(libs.plugins.kotlinAndroid).apply(false)
alias(libs.plugins.kotlinMultiplatform).apply(false)
alias(libs.plugins.kotlinCocoapods).apply(false)
alias(libs.plugins.compose.compiler).apply(false)
alias(libs.plugins.kotlinx.serialization) apply false
alias(libs.plugins.ksp) apply false
alias(libs.plugins.skie).apply(false)
alias(libs.plugins.kotlin.kapt).apply(false)
alias(libs.plugins.gradle.spotless) apply false
alias(libs.plugins.detekt) apply false
alias(libs.plugins.kotlinx.kover) apply false
}
subprojects {
tasks.withType<KotlinCompile> {
compilerOptions {
jvmTarget = JvmTarget.JVM_11
}
}
tasks.withType<KotlinCompilationTask<*>> {
compilerOptions {
freeCompilerArgs.addAll(
listOf(
"-opt-in=kotlin.RequiresOptIn",
"-opt-in=kotlinx.coroutines.ExperimentalCoroutinesApi",
"-opt-in=kotlinx.coroutines.FlowPreview",
),
)
}
}
apply<com.diffplug.gradle.spotless.SpotlessPlugin>()
fun isNonStable(version: String): Boolean {
val stableKeyword = listOf("RELEASE", "FINAL", "GA").any { version.uppercase().contains(it) }
val regex = "^[0-9,.v-]+(-r)?$".toRegex()
val isStable = stableKeyword || regex.matches(version)
return !isStable
}
fun isStable(version: String) = !isNonStable(version)
afterEvaluate {
tasks.withType<Test> {
testLogging {
showExceptions = true
showCauses = true
showStackTraces = true
showStandardStreams = true
events = EnumSet.of(
TestLogEvent.PASSED,
TestLogEvent.FAILED,
TestLogEvent.SKIPPED,
TestLogEvent.STANDARD_OUT,
TestLogEvent.STANDARD_ERROR,
)
exceptionFormat = TestExceptionFormat.FULL
}
}
}
}
allprojects {
// Apply the spotless plugin to all subprojects
apply<com.diffplug.gradle.spotless.SpotlessPlugin>()
configure<com.diffplug.gradle.spotless.SpotlessExtension> {
val ktlintVersion = rootProject.libs.versions.ktlint.get()
kotlin {
target("**/*.kt")
targetExclude("**/build/**/*.kt", "**/.gradle/**/*.kt")
ktlint(ktlintVersion)
.setEditorConfigPath(rootProject.file(".editorconfig"))
trimTrailingWhitespace()
indentWithSpaces()
endWithNewline()
}
format("xml") {
target("**/res/**/*.xml")
targetExclude("**/build/**/*.xml", "**/.idea/**/*.xml", "**/.gradle/**/*.xml")
trimTrailingWhitespace()
indentWithSpaces()
endWithNewline()
lineEndings = com.diffplug.spotless.LineEnding.UNIX
}
kotlinGradle {
target("**/*.gradle.kts", "*.gradle.kts")
targetExclude("**/build/**/*.kts", "**/.gradle/**/*.kts")
ktlint(ktlintVersion)
.setEditorConfigPath(rootProject.file(".editorconfig"))
trimTrailingWhitespace()
indentWithSpaces()
endWithNewline()
}
}
// Configure the test task to run in parallel
afterEvaluate {
tasks.withType<Test> {
maxParallelForks = (Runtime.getRuntime().availableProcessors() / 2)
.coerceAtLeast(1)
.also { println("Setting maxParallelForks to $it") }
testLogging {
showExceptions = true
showCauses = true
showStackTraces = true
showStandardStreams = true
events =
EnumSet.of(
TestLogEvent.PASSED,
TestLogEvent.FAILED,
TestLogEvent.SKIPPED,
TestLogEvent.STANDARD_OUT,
TestLogEvent.STANDARD_ERROR,
)
exceptionFormat = TestExceptionFormat.FULL
}
}
}
// Apply the detekt plugin to all subprojects
apply<io.gitlab.arturbosch.detekt.DetektPlugin>()
configure<io.gitlab.arturbosch.detekt.extensions.DetektExtension> {
source.from(files("src/"))
config.from(files("${rootProject.projectDir}/config/detekt/detekt.yml"))
allRules = true
buildUponDefaultConfig = true
parallel = true
autoCorrect = true
}
afterEvaluate {
dependencies {
"detektPlugins"(rootProject.libs.compose.rules.detekt)
}
}
}