-
Notifications
You must be signed in to change notification settings - Fork 270
Expand file tree
/
Copy pathbuild.gradle.kts
More file actions
176 lines (160 loc) · 6.84 KB
/
build.gradle.kts
File metadata and controls
176 lines (160 loc) · 6.84 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
174
175
176
plugins {
alias(libs.plugins.android.application) apply false
alias(libs.plugins.android.library) apply false
alias(libs.plugins.android.kotlin.multiplatform.library) apply false
alias(libs.plugins.kotlin.multiplatform) apply false
alias(libs.plugins.kotlin.android) apply false
alias(libs.plugins.kotlin.serialization) apply false
alias(libs.plugins.kotlin.compose) apply false
alias(libs.plugins.compose.multiplatform) apply false
alias(libs.plugins.ksp) apply false
alias(libs.plugins.sqldelight) apply false
alias(libs.plugins.ktlint) apply false
alias(libs.plugins.metro) apply false
}
allprojects {
apply(plugin = "org.jlleitschuh.gradle.ktlint")
configure<org.jlleitschuh.gradle.ktlint.KtlintExtension> {
filter {
exclude { element ->
element.file.path.contains("/build/")
}
}
}
// Workaround: ktlint-gradle filter doesn't reliably exclude generated sources
// added via KMP source sets. Exclude them by removing build dir from task sources.
afterEvaluate {
tasks.withType<org.jlleitschuh.gradle.ktlint.tasks.BaseKtLintCheckTask>().configureEach {
val buildDir = layout.buildDirectory.get().asFile
exclude { it.file.startsWith(buildDir) }
}
}
}
subprojects {
apply(plugin = "checkstyle")
dependencies {
"checkstyle"(rootProject.libs.checkstyle)
}
plugins.withId("org.jetbrains.kotlin.multiplatform") {
extensions.configure<org.jetbrains.kotlin.gradle.dsl.KotlinMultiplatformExtension> {
jvm()
@OptIn(org.jetbrains.kotlin.gradle.ExperimentalWasmDsl::class)
wasmJs {
browser()
}
compilerOptions {
freeCompilerArgs.add("-Xexpect-actual-classes")
}
}
// Library modules only need wasmJs compilation (klib) for app:web to consume.
// Disable wasmJs executable linking and test tasks — the IR linker is extremely
// slow and these modules get sufficient test coverage from jvmTest.
if (project.path != ":app:web") {
afterEvaluate {
tasks.configureEach {
val isWasmJs = name.contains("WasmJs", ignoreCase = true)
val isTestOrExe =
name.contains("Test", ignoreCase = true) ||
name.contains("Executable", ignoreCase = true)
if (isWasmJs && isTestOrExe) {
enabled = false
}
}
}
}
}
plugins.withId("org.jetbrains.compose") {
plugins.withId("org.jetbrains.kotlin.multiplatform") {
afterEvaluate {
val composeExt = extensions.findByType<org.jetbrains.compose.ComposeExtension>()
if (composeExt != null) {
extensions.configure<org.jetbrains.kotlin.gradle.dsl.KotlinMultiplatformExtension> {
if (targets.findByName("jvm") != null) {
sourceSets.named("jvmMain") {
dependencies {
implementation(composeExt.dependencies.desktop.currentOs)
}
}
}
}
}
}
}
}
configurations.configureEach {
resolutionStrategy {
force("com.google.errorprone:error_prone_annotations:2.28.0")
}
}
afterEvaluate {
tasks.named("check") {
dependsOn("checkstyle")
}
tasks.register<Checkstyle>("checkstyle") {
configFile = rootProject.file("config/checkstyle/checkstyle.xml")
source("src")
include("**/*.java")
exclude("**/gen/**")
classpath = files()
}
extensions.findByType<CheckstyleExtension>()?.apply {
isIgnoreFailures = false
}
}
// Pin compose resource package names to match the module path hierarchy
// (e.g. :transit:orca → farebot.transit.orca.generated.resources).
plugins.withId("org.jetbrains.compose") {
extensions.configure<org.jetbrains.compose.ComposeExtension> {
val pkg = "farebot" + project.path.replace(":", ".").replace("-", "_") + ".generated.resources"
(this as ExtensionAware).extensions.configure<org.jetbrains.compose.resources.ResourcesExtension> {
packageOfResClass = pkg
}
}
}
// Workaround: Compose Multiplatform's CopyResourcesToAndroidAssetsTask doesn't
// configure its outputDirectory with com.android.kotlin.multiplatform.library (AGP 9).
// Fix by assembling compose resources as Java classpath resources instead of Android
// assets. DefaultAndroidResourceReader falls back to ClassLoader.getResourceAsStream().
plugins.withId("com.android.kotlin.multiplatform.library") {
plugins.withId("org.jetbrains.compose") {
plugins.withId("org.jetbrains.kotlin.multiplatform") {
val resourceNamespace =
"farebot" + project.path.replace(":", ".").replace("-", "_") + ".generated.resources"
val outputBaseDir = layout.buildDirectory.dir("compose-android-classpath-resources")
val copyTask =
tasks.register<Copy>("copyComposeResourcesToAndroidClasspath") {
from(
layout.buildDirectory.dir(
"generated/compose/resourceGenerator/preparedResources/commonMain/composeResources",
),
)
into(outputBaseDir.map { it.dir("composeResources/$resourceNamespace") })
dependsOn("prepareComposeResourcesTaskForCommonMain")
}
afterEvaluate {
extensions.configure<org.jetbrains.kotlin.gradle.dsl.KotlinMultiplatformExtension> {
sourceSets.named("androidMain") {
resources.srcDir(outputBaseDir)
}
}
tasks.named("processAndroidMainJavaRes") {
dependsOn(copyTask)
}
}
}
}
}
plugins.withType<com.android.build.gradle.BasePlugin> {
@Suppress("DEPRECATION")
extensions.findByType<com.android.build.gradle.BaseExtension>()?.apply {
compileOptions {
sourceCompatibility = JavaVersion.VERSION_17
targetCompatibility = JavaVersion.VERSION_17
}
lintOptions {
isAbortOnError = true
disable("InvalidPackage", "MissingTranslation")
}
}
}
}