forked from GitLiveApp/firebase-kotlin-sdk
-
Notifications
You must be signed in to change notification settings - Fork 0
/
build.gradle.kts
268 lines (231 loc) · 9.78 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
import org.apache.tools.ant.taskdefs.condition.Os
import org.gradle.api.tasks.testing.logging.TestExceptionFormat
import org.gradle.api.tasks.testing.logging.TestLogEvent
plugins {
kotlin("multiplatform") version "1.5.31" apply false
id("base")
}
buildscript {
repositories {
google()
mavenCentral()
gradlePluginPortal()
maven {
url = uri("https://plugins.gradle.org/m2/")
}
}
dependencies {
classpath("com.android.tools.build:gradle:7.0.1")
classpath("com.adarshr:gradle-test-logger-plugin:2.1.1")
}
}
val targetSdkVersion by extra(30)
val minSdkVersion by extra(16)
tasks {
val updateVersions by registering {
dependsOn(
"firebase-app:updateVersion", "firebase-app:updateDependencyVersion",
"firebase-auth:updateVersion", "firebase-auth:updateDependencyVersion",
"firebase-common:updateVersion", "firebase-common:updateDependencyVersion",
"firebase-database:updateVersion", "firebase-database:updateDependencyVersion",
"firebase-firestore:updateVersion", "firebase-firestore:updateDependencyVersion",
"firebase-functions:updateVersion", "firebase-functions:updateDependencyVersion",
"firebase-config:updateVersion", "firebase-config:updateDependencyVersion"
)
}
}
subprojects {
group = "dev.gitlive"
apply(plugin="com.adarshr.test-logger")
repositories {
mavenLocal()
google()
mavenCentral()
}
tasks.withType<Sign>().configureEach {
onlyIf { !project.gradle.startParameter.taskNames.contains("publishToMavenLocal") }
}
tasks.whenTaskAdded {
enabled = when(name) {
"compileDebugUnitTestKotlinAndroid" -> false
"compileReleaseUnitTestKotlinAndroid" -> false
"testDebugUnitTest" -> false
"testReleaseUnitTest" -> false
else -> enabled
}
}
tasks {
val updateVersion by registering(Exec::class) {
commandLine("npm", "--allow-same-version", "--prefix", projectDir, "version", "${project.property("${project.name}.version")}")
}
val updateDependencyVersion by registering(Copy::class) {
mustRunAfter("updateVersion")
val from = file("package.json")
from.writeText(
from.readText()
.replace("firebase-common\": \"([^\"]+)".toRegex(), "firebase-common\": \"${project.property("firebase-common.version")}")
.replace("firebase-app\": \"([^\"]+)".toRegex(), "firebase-app\": \"${project.property("firebase-app.version")}")
)
}
val copyReadMe by registering(Copy::class) {
from(rootProject.file("README.md"))
into(file("$buildDir/node_module"))
}
val copyPackageJson by registering(Copy::class) {
from(file("package.json"))
into(file("$buildDir/node_module"))
}
val unzipJar by registering(Copy::class) {
val zipFile = File("$buildDir/libs", "${project.name}-js-${project.version}.jar")
from(this.project.zipTree(zipFile))
into("$buildDir/classes/kotlin/js/main/")
}
val copyJS by registering {
mustRunAfter("unzipJar", "copyPackageJson")
doLast {
val from = File("$buildDir/classes/kotlin/js/main/${rootProject.name}-${project.name}.js")
val into = File("$buildDir/node_module/${project.name}.js")
into.createNewFile()
into.writeText(
from.readText()
.replace("require('firebase-kotlin-sdk-", "require('@gitlive/")
// .replace("require('kotlinx-serialization-kotlinx-serialization-runtime')", "require('@gitlive/kotlinx-serialization-runtime')")
)
}
}
val copySourceMap by registering(Copy::class) {
from(file("$buildDir/classes/kotlin/js/main/${project.name}.js.map"))
into(file("$buildDir/node_module"))
}
val prepareForNpmPublish by registering {
dependsOn(
unzipJar,
copyPackageJson,
copySourceMap,
copyReadMe,
copyJS
)
}
val publishToNpm by creating(Exec::class) {
workingDir("$buildDir/node_module")
isIgnoreExitValue = true
if(Os.isFamily(Os.FAMILY_WINDOWS)) {
commandLine("cmd", "/c", "npm publish")
} else {
commandLine("npm", "publish")
}
}
withType<Test> {
testLogging {
showExceptions = true
exceptionFormat = TestExceptionFormat.FULL
showStandardStreams = true
showCauses = true
showStackTraces = true
events = setOf(
TestLogEvent.STARTED,
TestLogEvent.FAILED,
TestLogEvent.PASSED,
TestLogEvent.SKIPPED,
TestLogEvent.STANDARD_OUT,
TestLogEvent.STANDARD_ERROR
)
}
}
if (projectDir.resolve("src/nativeInterop/cinterop/Cartfile").exists()) { // skipping firebase-common module
listOf("bootstrap", "update").forEach {
task<Exec>("carthage${it.capitalize()}") {
group = "carthage"
executable = "carthage"
args(
it,
"--project-directory", projectDir.resolve("src/nativeInterop/cinterop"),
"--platform", "iOS",
"--cache-builds"
)
}
}
}
if (Os.isFamily(Os.FAMILY_MAC)) {
withType(org.jetbrains.kotlin.gradle.tasks.CInteropProcess::class) {
dependsOn("carthageBootstrap")
}
}
create("carthageClean", Delete::class.java) {
group = "carthage"
delete(
projectDir.resolve("src/nativeInterop/cinterop/Carthage"),
projectDir.resolve("src/nativeInterop/cinterop/Cartfile.resolved")
)
}
}
afterEvaluate {
// create the projects node_modules if they don't exist
if(!File("$buildDir/node_module").exists()) {
mkdir("$buildDir/node_module")
}
tasks.named<Delete>("clean") {
dependsOn("carthageClean")
}
dependencies {
"commonMainImplementation"("org.jetbrains.kotlinx:kotlinx-coroutines-core:1.5.2")
"androidMainImplementation"("org.jetbrains.kotlinx:kotlinx-coroutines-play-services:1.5.2")
"androidMainImplementation"(platform("com.google.firebase:firebase-bom:28.4.1"))
"commonTestImplementation"(kotlin("test-common"))
"commonTestImplementation"(kotlin("test-annotations-common"))
"commonTestImplementation"("org.jetbrains.kotlinx:kotlinx-coroutines-core:1.5.2")
"jsTestImplementation"(kotlin("test-js"))
"androidAndroidTestImplementation"(kotlin("test-junit"))
"androidAndroidTestImplementation"("junit:junit:4.13.2")
"androidAndroidTestImplementation"("androidx.test:core:1.4.0")
"androidAndroidTestImplementation"("androidx.test.ext:junit:1.1.3")
"androidAndroidTestImplementation"("androidx.test:runner:1.4.0")
}
}
apply(plugin="maven-publish")
apply(plugin="signing")
configure<PublishingExtension> {
repositories {
maven {
url = uri("https://oss.sonatype.org/service/local/staging/deploy/maven2")
credentials {
username = project.findProperty("sonatypeUsername") as String? ?: System.getenv("sonatypeUsername")
password = project.findProperty("sonatypePassword") as String? ?: System.getenv("sonatypePassword")
}
}
}
publications.all {
this as MavenPublication
pom {
name.set("firebase-kotlin-sdk")
description.set("The Firebase Kotlin SDK is a Kotlin-first SDK for Firebase. It's API is similar to the Firebase Android SDK Kotlin Extensions but also supports multiplatform projects, enabling you to use Firebase directly from your common source targeting iOS, Android or JS.")
url.set("https://github.com/GitLiveApp/firebase-kotlin-sdk")
inceptionYear.set("2019")
scm {
url.set("https://github.com/GitLiveApp/firebase-kotlin-sdk")
connection.set("scm:git:https://github.com/GitLiveApp/firebase-kotlin-sdk.git")
developerConnection.set("scm:git:https://github.com/GitLiveApp/firebase-kotlin-sdk.git")
tag.set("HEAD")
}
issueManagement {
system.set("GitHub Issues")
url.set("https://github.com/GitLiveApp/firebase-kotlin-sdk/issues")
}
developers {
developer {
name.set("Nicholas Bransby-Williams")
email.set("[email protected]")
}
}
licenses {
license {
name.set("The Apache Software License, Version 2.0")
url.set("http://www.apache.org/licenses/LICENSE-2.0.txt")
distribution.set("repo")
comments.set("A business-friendly OSS license")
}
}
}
}
}
}