-
Notifications
You must be signed in to change notification settings - Fork 327
Expand file tree
/
Copy pathbuild.gradle.kts
More file actions
279 lines (252 loc) · 11 KB
/
Copy pathbuild.gradle.kts
File metadata and controls
279 lines (252 loc) · 11 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
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
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
import org.jetbrains.kotlin.compose.compiler.gradle.ComposeCompilerGradlePluginExtension
import org.jetbrains.kotlin.gradle.dsl.JvmTarget
import org.jetbrains.kotlin.gradle.dsl.KotlinMultiplatformExtension
import org.jetbrains.kotlin.gradle.dsl.KotlinProjectExtension
import org.jetbrains.kotlin.gradle.dsl.abi.BinariesSource
import org.jetbrains.kotlin.gradle.dsl.abi.ExperimentalAbiValidation
import org.jetbrains.kotlin.gradle.plugin.mpp.KotlinNativeTarget
import org.jetbrains.kotlin.gradle.plugin.mpp.TestExecutable
import org.jetbrains.kotlin.gradle.tasks.KotlinJvmCompile
buildscript {
repositories {
// maven { setUrl("https://maven.aliyun.com/repository/public") } // central、jcenter
// maven { setUrl("https://maven.aliyun.com/repository/google") } // google
// maven { setUrl("https://repo.huaweicloud.com/repository/maven/") } // central、google、jcenter
// maven("https://maven.pkg.jetbrains.space/public/p/compose/dev")
gradlePluginPortal()
mavenCentral()
google()
}
dependencies {
classpath(libs.gradlePlugin.android)
classpath(libs.gradlePlugin.androidxNavigationSafeArgs)
classpath(libs.gradlePlugin.buildkonfig)
classpath(libs.gradlePlugin.jetbrainsCompose)
classpath(libs.gradlePlugin.kotlin)
classpath(libs.gradlePlugin.kotlinComposeCompiler)
classpath(libs.gradlePlugin.kotlinSerialization)
classpath(libs.gradlePlugin.kotlinxAtomicfu)
classpath(libs.gradlePlugin.kotlinxCover)
classpath(libs.gradlePlugin.mavenPublish)
}
}
plugins {
alias(libs.plugins.dokka)
}
tasks.register("cleanRootBuild", Delete::class) {
description = "Clean the root build directory."
delete(rootProject.project.layout.buildDirectory.get().asFile.absolutePath)
}
// Aggregate dokka documentation for all submodules
dependencies {
for (module in publicModules) {
dokka(project(":$module"))
}
}
allprojects {
repositories {
// maven { setUrl("https://maven.aliyun.com/repository/public") } // central、jcenter
// maven { setUrl("https://maven.aliyun.com/repository/google") } // google
// maven { setUrl("https://repo.huaweicloud.com/repository/maven/") } // central、google、jcenter
mavenCentral()
google()
maven { setUrl("https://www.jitpack.io") }
// maven { setUrl("https://s01.oss.sonatype.org/content/repositories/snapshots") }
// mavenLocal()
}
// Target JVM 11.
afterEvaluate {
tasks.withType<JavaCompile>().configureEach {
sourceCompatibility = JavaVersion.VERSION_11.toString()
targetCompatibility = JavaVersion.VERSION_11.toString()
options.compilerArgs = options.compilerArgs + "-Xlint:-options"
}
tasks.withType<KotlinJvmCompile>().configureEach {
compilerOptions.jvmTarget = JvmTarget.JVM_11
}
}
// 'expect'/'actual' classes (including interfaces, objects, annotations, enums, and 'actual' typealiases) are in Beta. Consider using the '-Xexpect-actual-classes' flag to suppress this warning.
// Also see: https://youtrack.jetbrains.com/issue/KT-61573
plugins.withId("org.jetbrains.kotlin.multiplatform") {
extensions.configure<KotlinMultiplatformExtension> {
targets.configureEach {
compilations.configureEach {
compileTaskProvider.configure {
compilerOptions {
freeCompilerArgs.addAll(listOf("-Xexpect-actual-classes"))
}
}
}
}
}
}
// Can't dispatch to the main thread in native tests. https://youtrack.jetbrains.com/issue/KT-53129
plugins.withId("org.jetbrains.kotlin.multiplatform") {
extensions.configure<KotlinMultiplatformExtension> {
targets.withType<KotlinNativeTarget> {
if (konanTarget.family.isAppleFamily) {
binaries.withType<TestExecutable> {
freeCompilerArgs += listOf(
"-e",
"com.github.panpf.sketch.test.utils.mainBackground"
)
}
}
}
}
}
// Add compilation configuration for Compose module
plugins.withId("org.jetbrains.kotlin.plugin.compose") {
extensions.configure<ComposeCompilerGradlePluginExtension> {
stabilityConfigurationFiles.add {
rootDir.resolve("sketch-core/compose_compiler_config.conf")
}
}
}
/*
* Run the `./gradlew clean :sketch-compose:assembleRelease -PcomposeCompilerReports=true` command to generate a report,
* which is located in the `project/module/build/compose_compiler` directory.
*
* Interpretation of the report: https://developer.android.com/jetpack/compose/performance/stability/diagnose#kotlin
*/
if (project.findProperty("composeCompilerReports") == "true") {
plugins.withId("org.jetbrains.kotlin.plugin.compose") {
extensions.configure<ComposeCompilerGradlePluginExtension> {
val outputDir = layout.buildDirectory.dir("compose_compiler").get().asFile
metricsDestination = outputDir
reportsDestination = outputDir
}
}
}
// jetbrains-compose bug https://youtrack.jetbrains.com/issue/CMP-5831
configurations.all {
resolutionStrategy.eachDependency {
if (requested.group == "org.jetbrains.kotlinx" && requested.name == "atomicfu") {
useVersion(libs.versions.kotlinx.atomicfu.get())
}
}
}
// Uninstall test APKs after running instrumentation tests.
tasks.configureEach {
if (name == "connectedDebugAndroidTest") {
finalizedBy("uninstallDebugAndroidTest")
}
}
// Configure publish plugin for all publishable library modules
val isPublishableModule =
hasProperty("POM_ARTIFACT_ID") // configured in the project/gradle.properties file
if (isPublishableModule) {
apply { plugin("com.vanniktech.maven.publish") }
configure<com.vanniktech.maven.publish.MavenPublishBaseExtension> {
version = property("versionName").toString()
if (hasProperty("signing.keyId") // configured in the ~/.gradle/gradle.properties file
&& hasProperty("signing.password") // configured in the ~/.gradle/gradle.properties file
&& hasProperty("signing.secretKeyRingFile") // configured in the ~/.gradle/gradle.properties file
) {
signAllPublications()
} else if (
System.getenv("ORG_GRADLE_PROJECT_signingInMemoryKey").orEmpty()
.isNotEmpty() // configured in the GitHub workflow env
&& System.getenv("ORG_GRADLE_PROJECT_signingInMemoryKeyPassword").orEmpty()
.isNotEmpty() // configured in the GitHub workflow env
) {
signAllPublications()
}
}
}
// Configure Dokka plugin for all publishable library modules
if (isPublishableModule) {
apply { plugin("org.jetbrains.dokka") }
}
// Enable ABI validation for all publishable library modules.
if (isPublishableModule) {
configureAbiValidation()
configureAndroidAbiValidation()
}
}
@OptIn(ExperimentalAbiValidation::class)
fun Project.configureAbiValidation() {
// TODO The abiValidation feature does not yet support kmp Android targets and pure Android modules. https://youtrack.jetbrains.com/issue/KT-78025
afterEvaluate {
val kotlinExtension =
extensions.findByType<KotlinProjectExtension>() ?: return@afterEvaluate
kotlinExtension.abiValidation {
referenceDumpDir.set(layout.projectDirectory.dir("api"))
binariesSource.set(BinariesSource.MAIN_COMPILATION)
}
}
}
fun Project.configureAndroidAbiValidation() {
plugins.withId("com.android.library") {
afterEvaluate {
configureAndroidAbiValidation(
subdirectoryName = "",
dependencyTaskNames = listOf(
"compileReleaseKotlin",
"compileReleaseJavaWithJavac",
),
classfiles = files(
layout.buildDirectory.dir("intermediates/built_in_kotlinc/release/compileReleaseKotlin/classes"),
layout.buildDirectory.dir("intermediates/javac/release/compileReleaseJavaWithJavac/classes"),
),
)
}
}
plugins.withId("com.android.kotlin.multiplatform.library") {
afterEvaluate {
configureAndroidAbiValidation(
subdirectoryName = "android",
dependencyTaskNames = listOf(
"compileAndroidMain",
"compileAndroidMainJavaWithJavac",
),
classfiles = files(
layout.buildDirectory.dir("classes/kotlin/android/main"),
layout.buildDirectory.dir("classes/java/android/main"),
layout.buildDirectory.dir("intermediates/javac/androidMain/classes"),
),
)
}
}
}
private fun Project.configureAndroidAbiValidation(
subdirectoryName: String,
dependencyTaskNames: List<String>,
classfiles: FileCollection,
) {
val dependencyTasks = tasks.matching { it.name in dependencyTaskNames }
tasks.matching { it.name == "internalDumpKotlinAbi" }.configureEach {
dependsOn(dependencyTasks)
configureKotlinAbiDumpInput(subdirectoryName, classfiles)
}
}
private fun Task.configureKotlinAbiDumpInput(
subdirectoryName: String,
classfiles: FileCollection,
) {
val dumpTaskClass = javaClass
val getJvm = runCatching { dumpTaskClass.getMethod("getJvm") }.getOrNull() ?: return
val jvmProperty = getJvm.invoke(this)
val propertyClass = jvmProperty.javaClass
val get = propertyClass.getMethod("get")
val set = propertyClass.getMethod("set", Iterable::class.java)
val existingEntries = mutableListOf<Any>()
val currentEntries = get.invoke(jvmProperty)
if (currentEntries is Iterable<*>) {
currentEntries.filterNotNullTo(existingEntries)
} else {
return
}
val entryClass = existingEntries.firstOrNull()?.javaClass
?: runCatching {
dumpTaskClass.classLoader.loadClass(
$$"org.jetbrains.kotlin.gradle.tasks.abi.KotlinAbiDumpTaskImpl$JvmTargetInfo",
)
}.getOrNull()
?: return
val getSubdirectoryName = entryClass.getMethod("getSubdirectoryName")
if (existingEntries.any { getSubdirectoryName.invoke(it) == subdirectoryName }) return
val constructor = entryClass.getConstructor(String::class.java, FileCollection::class.java)
existingEntries.add(constructor.newInstance(subdirectoryName, classfiles))
set.invoke(jvmProperty, existingEntries)
}