-
Notifications
You must be signed in to change notification settings - Fork 9
/
build.gradle.kts
383 lines (345 loc) · 10.9 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
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
import com.android.build.gradle.LibraryExtension
import com.liftric.vault.GetVaultSecretTask
import org.jetbrains.kotlin.gradle.targets.native.tasks.KotlinNativeSimulatorTest
import org.jetbrains.kotlin.gradle.tasks.*
plugins {
kotlin("multiplatform") version libs.versions.kotlin
alias(libs.plugins.kotlin.serialization)
id("com.android.library") version libs.versions.android.tools.gradle
alias(libs.plugins.definitions)
alias(libs.plugins.npm.publishing)
alias(libs.plugins.versioning)
alias(libs.plugins.vault.client)
id("maven-publish")
id("signing")
}
repositories {
mavenCentral()
google()
gradlePluginPortal()
}
java {
sourceCompatibility = JavaVersion.VERSION_1_8
targetCompatibility = JavaVersion.VERSION_1_8
}
kotlin {
ios {
binaries.framework()
}
iosSimulatorArm64()
androidTarget() {
publishAllLibraryVariants()
}
jvm()
js(IR) {
generateTypeScriptDefinitions()
browser {
testTask {
useMocha {
timeout = "10s"
}
}
}
binaries.library()
compilations.all {
compileTaskProvider.configure {
compilerOptions.freeCompilerArgs.add("-Xir-minimized-member-names=false")
}
}
}
sourceSets {
val commonMain by getting {
dependencies {
api(libs.ktor.client.core)
api(libs.kotlinx.coroutines)
api(libs.kotlinx.serialization)
}
}
val commonTest by getting {
kotlin.srcDir("${buildDir}/gen")
dependencies {
implementation(kotlin("test"))
implementation(kotlin("test-common"))
implementation(kotlin("test-annotations-common"))
}
}
val androidMain by getting {
dependencies {
api(libs.ktor.client.android)
}
}
val jvmMain by getting {
dependencies {
api(libs.ktor.client.jvm)
}
}
val androidUnitTest by getting {
dependencies {
implementation(libs.roboelectric)
implementation(kotlin("test"))
implementation(kotlin("test-junit"))
implementation(libs.androidx.test.core)
implementation(libs.opt.java)
}
}
val jvmTest by getting {
dependencies {
implementation(kotlin("test"))
implementation(kotlin("test-junit"))
implementation(libs.opt.java)
}
}
val iosMain by getting {
dependencies {
api(libs.ktor.client.darwin)
}
}
val iosTest by getting
val iosSimulatorArm64Main by getting {
dependsOn(iosMain)
}
val iosSimulatorArm64Test by getting {
dependsOn(iosTest)
}
val jsMain by getting {
dependencies {
api(libs.ktor.client.js)
}
}
val jsTest by getting {
dependencies {
implementation(kotlin("test-js"))
}
}
all {
languageSettings {
optIn("kotlinx.serialization.ExperimentalSerializationApi")
optIn("kotlin.js.ExperimentalJsExport")
optIn("kotlin.RequiresOptIn")
}
}
}
}
configure<LibraryExtension> {
defaultConfig.apply {
compileSdk = 30
minSdkVersion(21)
targetSdkVersion(30)
testInstrumentationRunner = "org.robolectric.RobolectricTestRunner"
}
compileOptions {
sourceCompatibility = JavaVersion.VERSION_11
targetCompatibility = JavaVersion.VERSION_11
}
testOptions {
unitTests.apply {
isIncludeAndroidResources = true
isReturnDefaultValues = true
}
}
namespace = "com.liftric.cognito.idp"
publishing {
multipleVariants {
allVariants()
withJavadocJar()
}
}
}
group = "com.liftric"
version = with(versioning.info) {
if (branch == "HEAD" && dirty.not()) tag else full
}
afterEvaluate {
project.publishing.publications.withType(MavenPublication::class.java).forEach {
it.groupId = group.toString()
}
}
tasks {
withType(KotlinNativeSimulatorTest::class) {
filter.excludeTestsMatching("com.liftric.cognito.idp.IdentityProviderClientTests")
}
val testSecrets by creating(GetVaultSecretTask::class) {
secretPath.set("secret/apps/smartest/shared/cognito")
}
val createJsEnvHack by creating {
outputs.dir("$buildDir/gen")
if (System.getenv("region") == null || System.getenv("clientId") == null) {
// github ci provides region and clientId envs, locally we'll use vault directly
dependsOn(testSecrets)
}
doFirst {
val (clientId, region) = with(testSecrets.secret.get()) {
((System.getenv("clientId") ?: this["client_id_dev"].toString()) to
(System.getenv("region") ?: this["client_region_dev"].toString()))
}
mkdir("$buildDir/gen")
with(File("$buildDir/gen/env.kt")) {
createNewFile()
writeText(
"""
val env = mapOf(
"region" to "$region",
"clientId" to "$clientId",
)
""".trimIndent()
)
}
}
}
withType<KotlinCompileCommon> {
dependsOn(createJsEnvHack)
}
withType<KotlinCompile> {
kotlinOptions {
jvmTarget = "11"
languageVersion = "1.5"
freeCompilerArgs = listOf(
"-Xinline-classes"
)
}
}
/**
* Ugly atomicfu export hack: Coroutines core needs atomicfu-js, which generates broken d.ts entries. Excluding
* atomicfu-js breaks the ktor client and filtering d.ts types in the IR compile is currently not possible... so let's
* just rip it out after the fact
*
* The build/js/packages/cognito-idp/kotlin/cognito-idp.d.ts file should now be without errors and usable from typescript
*/
val cleanTypescriptTypes by creating {
fun MutableList<String>.removeFromTill(from: String, till: String) {
val fromIndex = indexOfFirst { it == from }
val tillIndex = indexOfFirst { it == till }
if (fromIndex == -1 || tillIndex == -1) {
println("looks like from='$from' till='$till' already scraped")
return
}
println("removeFromTill from='$from' till='$till' fromIndex=$fromIndex")
println("removeFromTill from='$from' till='$till' tillIndex=$tillIndex")
(fromIndex..tillIndex).forEach {
removeAt(fromIndex)
}
}
val dTsFile = file("$buildDir/js/packages/cognito-idp/kotlin/cognito-idp.d.ts")
inputs.file(dTsFile)
outputs.file(dTsFile)
doLast {
val dTs = dTsFile.readLines().toMutableList()
dTs.removeFromTill("export namespace kotlinx.atomicfu {", "}")
dTs.removeFromTill("export namespace io.ktor.util {", "}")
dTsFile.writeText(dTs.joinToString("\n"))
}
}
val jsBrowserProductionLibraryDistribution by existing {
finalizedBy(cleanTypescriptTypes)
}
val jsProductionLibraryCompileSync by existing {
finalizedBy(cleanTypescriptTypes)
}
}
val ossrhUsername: String? by project
val ossrhPassword: String? by project
val javadocJar by tasks.registering(Jar::class) {
archiveClassifier.set("javadoc")
}
publishing {
repositories {
maven {
name = "sonatype"
setUrl("https://s01.oss.sonatype.org/service/local/staging/deploy/maven2/")
credentials {
username = ossrhUsername
password = ossrhPassword
}
}
}
publications.withType<MavenPublication> {
artifact(javadocJar.get())
pom {
name.set(project.name)
description.set("Lightweight AWS Cognito Identity Provider client for Kotlin Multiplatform projects.")
url.set("https://github.com/liftric/cognito-idp")
licenses {
license {
name.set("MIT")
url.set("https://github.com/liftric/cognito-idp/blob/master/LICENSE")
}
}
developers {
developer {
id.set("benjohnde")
name.set("Ben John")
email.set("[email protected]")
}
developer {
id.set("ingwersaft")
name.set("Marcel Kesselring")
email.set("[email protected]")
}
}
scm {
url.set("https://github.com/liftric/cognito-idp")
}
}
}
}
val npmAccessKey: String? by project
npmPublish {
organization.set("liftric")
access.set(PUBLIC)
readme.set(rootProject.file("README.md"))
packages {
named("js") {
packageName.set(project.name)
packageJson {
keywords.set(
listOf(
"kotlin",
"cognito",
"identity-provider",
"liftric",
"aws"
)
)
license.set("MIT")
description.set("Lightweight AWS Cognito Identity Provider client.")
homepage.set("https://github.com/liftric/cognito-idp")
}
}
}
registries {
npmjs {
uri.set(uri("https://registry.npmjs.org"))
authToken.set(npmAccessKey)
}
}
}
signing {
val signingKey: String? by project
val signingPassword: String? by project
useInMemoryPgpKeys(signingKey, signingPassword)
sign(publishing.publications)
}
vault {
vaultAddress.set("https://dark-lord.liftric.io")
if (System.getenv("CI") == null) {
vaultTokenFilePath.set("${System.getProperty("user.home")}/.vault-token")
} else {
vaultToken.set(System.getenv("VAULT_TOKEN"))
}
}
tasks {
afterEvaluate {
val signingTasks = filter { it.name.startsWith("sign") }
all {
// lets bruteforce this until the plugins play along nicely again
if (name.contains("compile", true) && name.contains("kotlin", true)) {
dependsOn("createJsEnvHack")
}
if (name.startsWith("publish")) {
signingTasks.forEach { signTask ->
dependsOn(signTask)
}
}
}
}
}