-
Notifications
You must be signed in to change notification settings - Fork 671
/
build.gradle.kts
264 lines (237 loc) · 9.75 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
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
import coil3.enableComposeMetrics
import coil3.groupId
import coil3.publicModules
import coil3.versionName
import com.diffplug.gradle.spotless.SpotlessExtension
import com.diffplug.gradle.spotless.SpotlessExtensionPredeclare
import dev.drewhamilton.poko.gradle.PokoPluginExtension
import kotlinx.validation.ApiValidationExtension
import kotlinx.validation.ExperimentalBCVApi
import org.jetbrains.dokka.gradle.DokkaMultiModuleTask
import org.jetbrains.dokka.gradle.DokkaTaskPartial
import org.jetbrains.kotlin.compose.compiler.gradle.ComposeCompilerGradlePluginExtension
import org.jetbrains.kotlin.compose.compiler.gradle.ComposeFeatureFlag
import org.jetbrains.kotlin.gradle.dsl.JvmTarget
import org.jetbrains.kotlin.gradle.dsl.KotlinMultiplatformExtension
import org.jetbrains.kotlin.gradle.plugin.KotlinPlatformType
import org.jetbrains.kotlin.gradle.tasks.KotlinJvmCompile
buildscript {
repositories {
google()
mavenCentral()
}
dependencies {
classpath(libs.gradlePlugin.android)
classpath(libs.gradlePlugin.atomicFu)
classpath(libs.gradlePlugin.jetbrainsCompose)
classpath(libs.gradlePlugin.composeCompiler)
classpath(libs.gradlePlugin.kotlin)
classpath(libs.gradlePlugin.mavenPublish)
classpath(libs.gradlePlugin.paparazzi)
classpath(libs.gradlePlugin.roborazzi)
}
}
plugins {
alias(libs.plugins.baselineProfile) apply false
alias(libs.plugins.binaryCompatibility)
alias(libs.plugins.dokka)
alias(libs.plugins.poko) apply false
alias(libs.plugins.spotless)
}
extensions.configure<ApiValidationExtension> {
nonPublicMarkers += "coil3/annotation/InternalCoilApi"
ignoredProjects += project.subprojects.mapNotNull { project ->
if (project.name in publicModules) null else project.name
}
@OptIn(ExperimentalBCVApi::class)
klib {
enabled = true
}
}
tasks.withType<DokkaMultiModuleTask>().configureEach {
outputDirectory = layout.projectDirectory.dir("docs/api")
}
allprojects {
repositories {
google()
mavenCentral()
}
// Necessary to publish to Maven.
group = groupId
version = versionName
// Target JVM 8.
tasks.withType<JavaCompile>().configureEach {
sourceCompatibility = JavaVersion.VERSION_1_8.toString()
targetCompatibility = JavaVersion.VERSION_1_8.toString()
options.compilerArgs = options.compilerArgs + "-Xlint:-options"
}
tasks.withType<KotlinJvmCompile>().configureEach {
compilerOptions.jvmTarget = JvmTarget.JVM_1_8
}
tasks.withType<DokkaTaskPartial>().configureEach {
dokkaSourceSets.configureEach {
jdkVersion = 8
failOnWarning = true
skipDeprecated = true
suppressInheritedMembers = true
externalDocumentationLink(
url = "https://developer.android.com/reference/",
)
externalDocumentationLink(
url = "https://kotlinlang.org/api/kotlinx.coroutines/",
)
externalDocumentationLink(
url = "https://jetbrains.github.io/skiko/",
packageListUrl = "https://jetbrains.github.io/skiko/skiko/package-list",
)
externalDocumentationLink(
url = "https://api.ktor.io/",
)
externalDocumentationLink(
url = "https://kotlinlang.org/api/kotlinx-datetime/",
packageListUrl = "https://kotlinlang.org/api/kotlinx-datetime/kotlinx-datetime/package-list",
)
externalDocumentationLink(
url = "https://square.github.io/okio/3.x/okio/",
packageListUrl = "https://square.github.io/okio/3.x/okio/okio/package-list",
)
externalDocumentationLink(
url = "https://square.github.io/okhttp/5.x/okhttp/okhttp3/",
packageListUrl = "https://square.github.io/okhttp/5.x/package-list",
)
}
}
// Uninstall test APKs after running instrumentation tests.
tasks.configureEach {
if (name == "connectedDebugAndroidTest") {
finalizedBy("uninstallDebugAndroidTest")
}
}
apply(plugin = "com.diffplug.spotless")
val configureSpotless: SpotlessExtension.() -> Unit = {
kotlin {
target("**/*.kt", "**/*.kts")
ktlint(libs.versions.ktlint.get()).editorConfigOverride(ktlintRules)
endWithNewline()
indentWithSpaces()
trimTrailingWhitespace()
}
}
if (project === rootProject) {
spotless { predeclareDeps() }
extensions.configure<SpotlessExtensionPredeclare>(configureSpotless)
} else {
extensions.configure(configureSpotless)
}
plugins.withId("org.jetbrains.kotlin.plugin.compose") {
extensions.configure<ComposeCompilerGradlePluginExtension> {
featureFlags.addAll(
ComposeFeatureFlag.OptimizeNonSkippingGroups,
)
stabilityConfigurationFiles.add {
rootDir.resolve("coil-core/compose_compiler_config.conf")
}
if (enableComposeMetrics && name in publicModules) {
val outputDir = layout.buildDirectory.dir("composeMetrics").get().asFile
metricsDestination = outputDir
reportsDestination = outputDir
}
}
}
plugins.withId("dev.drewhamilton.poko") {
extensions.configure<PokoPluginExtension> {
pokoAnnotation = "coil3/annotation/Poko"
}
}
// https://youtrack.jetbrains.com/issue/CMP-5831
configurations.all {
resolutionStrategy.eachDependency {
if (requested.group == "org.jetbrains.kotlinx" && requested.name == "atomicfu") {
useVersion(libs.versions.atomicfu.get())
}
}
}
applyOkioJsTestWorkaround()
}
private val ktlintRules = buildMap {
put("ktlint_code_style", "intellij_idea")
put("ktlint_standard_annotation", "disabled")
put("ktlint_standard_blank-line-before-declaration", "disabled")
put("ktlint_standard_class-signature", "disabled")
put("ktlint_standard_filename", "disabled")
put("ktlint_standard_function-expression-body", "disabled")
put("ktlint_standard_function-signature", "disabled")
put("ktlint_standard_function-literal", "disabled")
put("ktlint_standard_indent", "disabled")
put("ktlint_standard_max-line-length", "disabled")
put("ktlint_standard_no-blank-line-in-list", "disabled")
put("ktlint_standard_no-empty-first-line-in-class-body", "disabled")
put("ktlint_standard_spacing-between-declarations-with-annotations", "disabled")
put("ktlint_standard_string-template-indent", "disabled")
put("ktlint_standard_trailing-comma-on-call-site", "disabled")
put("ktlint_standard_trailing-comma-on-declaration-site", "disabled")
put("ktlint_standard_try-catch-finally-spacing", "disabled")
put("ktlint_standard_backing-property-naming", "disabled")
put("ktlint_standard_function-naming", "disabled")
put("ktlint_standard_property-naming", "disabled")
put("ktlint_standard_type-argument-comment", "disabled")
put("ktlint_standard_type-parameter-comment", "disabled")
put("ktlint_standard_value-argument-comment", "disabled")
put("ktlint_standard_value-parameter-comment", "disabled")
put("ktlint_standard_argument-list-wrapping", "disabled")
put("ktlint_standard_binary-expression-wrapping", "disabled")
put("ktlint_standard_condition-wrapping", "disabled")
put("ktlint_standard_context-receiver-wrapping", "disabled")
put("ktlint_standard_enum-wrapping", "disabled")
put("ktlint_standard_if-else-wrapping", "disabled")
put("ktlint_standard_multiline-expression-wrapping", "disabled")
put("ktlint_standard_parameter-wrapping", "disabled")
put("ktlint_standard_parameter-list-wrapping", "disabled")
put("ktlint_standard_property-wrapping", "disabled")
put("ktlint_standard_statement-wrapping", "disabled")
put("ktlint_standard_wrapping", "disabled")
}
// https://github.com/square/okio/issues/1163
fun Project.applyOkioJsTestWorkaround() {
if (":samples" in displayName) {
// The polyfills cause issues with the samples.
return
}
plugins.withId("org.jetbrains.kotlin.multiplatform") {
val applyNodePolyfillPlugin by lazy {
tasks.register("applyNodePolyfillPlugin") {
val applyPluginFile = projectDir
.resolve("webpack.config.d/applyNodePolyfillPlugin.js")
onlyIf {
!applyPluginFile.exists()
}
doLast {
applyPluginFile.parentFile.mkdirs()
applyPluginFile.writeText(
"""
const NodePolyfillPlugin = require("node-polyfill-webpack-plugin");
config.plugins.push(new NodePolyfillPlugin());
""".trimIndent(),
)
}
}
}
extensions.configure<KotlinMultiplatformExtension> {
sourceSets {
targets.configureEach {
compilations.configureEach {
if (platformType == KotlinPlatformType.js && name == "test") {
tasks
.getByName(compileKotlinTaskName)
.dependsOn(applyNodePolyfillPlugin)
dependencies {
implementation(devNpm("node-polyfill-webpack-plugin", "^2.0.1"))
}
}
}
}
}
}
}
}
private val composePlugin = "plugin:androidx.compose.compiler.plugins.kotlin"