Skip to content

Commit 849a19f

Browse files
authored
Merge pull request #413 from GitLiveApp/update-jvm-target
Add jvm target using the firebase-java-sdk
2 parents 4310612 + f9d77ba commit 849a19f

File tree

51 files changed

+725
-244
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

51 files changed

+725
-244
lines changed

README.md

Lines changed: 8 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,14 @@
11
<h1 align="left">Firebase Kotlin SDK <img alt="GitHub last commit" src="https://img.shields.io/github/last-commit/gitliveapp/firebase-kotlin-sdk?style=flat-square"> <a href="https://git.live"><img src="https://img.shields.io/badge/collaborate-on%20gitlive-blueviolet?style=flat-square"></a></h1>
22
<img align="left" width="75px" src="https://avatars2.githubusercontent.com/u/42865805?s=200&v=4">
33
<b>Built and maintained with 🧡 by <a href="https://git.live">GitLive</a></b><br/>
4-
<i>Real-time code collaboration inside any IDE</i><br/>
4+
<i>Development teams merge faster with GitLive</i><br/>
55
<br/>
66
<br/>
7-
The Firebase Kotlin SDK is a Kotlin-first SDK for Firebase. It's API is similar to the <a href="https://firebase.github.io/firebase-android-sdk/reference/kotlin/firebase-ktx/">Firebase Android SDK Kotlin Extensions</a> but also supports multiplatform projects, enabling you to use Firebase directly from your common source targeting <strong>iOS</strong>, <strong>Android</strong> or <strong>JS</strong>.
7+
The Firebase Kotlin SDK is a Kotlin-first SDK for Firebase. It's API is similar to the
8+
<a href="https://firebase.github.io/firebase-android-sdk/reference/kotlin/firebase-ktx/">Firebase Android SDK Kotlin Extensions</a>
9+
but also supports multiplatform projects, enabling you to use Firebase directly from your common source targeting
10+
<strong>iOS</strong>, <strong>Android</strong>, <strong>Desktop</strong> or <strong>Web</strong>, enabling the use of
11+
Firebase as a backend for<a href="https://www.jetbrains.com/lp/compose-multiplatform/">Compose Multiplatform</a>, for example.
812

913
## Available libraries
1014

@@ -23,9 +27,6 @@ The following libraries are available for the various Firebase products.
2327
| [Performance](https://firebase.google.com/docs/perf-mon) | [`dev.gitlive:firebase-perf:1.8.2`](https://search.maven.org/artifact/dev.gitlive/firebase-perf/1.8.2/pom) | [![1%](https://img.shields.io/badge/-1%25-orange?style=flat-square)](/firebase-perf/src/commonMain/kotlin/dev/gitlive/firebase/perf/performance.kt) |
2428
| [Crashlytics](https://firebase.google.com/docs/crashlytics) | [`dev.gitlive:firebase-crashlytics:1.8.2`](https://search.maven.org/artifact/dev.gitlive/firebase-crashlytics/1.8.2/pom) | [![80%](https://img.shields.io/badge/-1%25-orange?style=flat-square)](/firebase-crashlytics/src/commonMain/kotlin/dev/gitlive/firebase/crashlytics/crashlytics.kt) |
2529

26-
27-
28-
2930
Is the Firebase library or API you need missing? [Create an issue](https://github.com/GitLiveApp/firebase-kotlin-sdk/issues/new?labels=API+coverage&template=increase-api-coverage.md&title=Add+%5Bclass+name%5D.%5Bfunction+name%5D+to+%5Blibrary+name%5D+for+%5Bplatform+names%5D) to request additional API coverage or be awesome and [submit a PR](https://github.com/GitLiveApp/firebase-kotlin-sdk/fork)
3031

3132
## Kotlin-first design
@@ -205,6 +206,8 @@ In cases where it makes sense, such as Firebase Functions HTTPS Callable, operat
205206

206207
The Firebase Kotlin SDK provides a common API to access Firebase for projects targeting *iOS*, *Android* and *JS* meaning you can use Firebase directly in your common code. Under the hood, the SDK achieves this by binding to the respective official Firebase SDK for each supported platform.
207208

209+
It uses the <a href="https://github.com/GitLiveApp/firebase-java-sdk">Firebase Java SDK</a> to support the JVM target.
210+
208211
### Accessing the underlying Firebase SDK
209212

210213
In some cases you might want to access the underlying official Firebase SDK in platform specific code, for example when the common API is missing the functionality you need. For this purpose each class in the SDK has `android`, `ios` and `js` properties which holds the equivalent object of the underlying official Firebase SDK.
@@ -217,25 +220,6 @@ These properties are only accessible from the equivalent target's source set. Fo
217220
.build()
218221
```
219222

220-
### NPM modules
221-
222-
If you are building a Kotlin multiplatform library which will be consumed from JS code you may need to include the SDK in your `package.json`, you can do it as follows:
223-
224-
```json
225-
"dependencies": {
226-
"@gitlive/firebase-auth": "1.8.2",
227-
"@gitlive/firebase-config": "1.8.2",
228-
"@gitlive/firebase-database": "1.8.2",
229-
"@gitlive/firebase-firestore": "1.8.2",
230-
"@gitlive/firebase-functions": "1.8.2",
231-
"@gitlive/firebase-installations": "1.8.2",
232-
"@gitlive/firebase-messaging": "1.8.2",
233-
"@gitlive/firebase-storage": "1.8.2"
234-
"@gitlive/firebase-perf": "1.8.2"
235-
"@gitlive/firebase-crashlytics": "1.8.2"
236-
}
237-
```
238-
239223
## Contributing
240224
If you'd like to contribute to this project then you can fork this repository.
241225
You can build and test the project locally.

build.gradle.kts

Lines changed: 7 additions & 61 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,3 @@
1-
import org.apache.tools.ant.taskdefs.condition.Os
21
import org.gradle.api.tasks.testing.logging.TestExceptionFormat
32
import org.gradle.api.tasks.testing.logging.TestLogEvent
43

@@ -63,7 +62,7 @@ subprojects {
6362
}
6463

6564
tasks.withType<Sign>().configureEach {
66-
onlyIf { !project.gradle.startParameter.taskNames.contains("publishToMavenLocal") }
65+
onlyIf { !project.gradle.startParameter.taskNames.any { "MavenLocal" in it } }
6766
}
6867

6968
val skipPublishing = project.name == "test-utils" // skip publishing for test utils
@@ -103,68 +102,9 @@ subprojects {
103102
.replace("firebase-app\": \"([^\"]+)".toRegex(), "firebase-app\": \"${project.property("firebase-app.version")}")
104103
)
105104
}
106-
107-
val copyReadMe by registering(Copy::class) {
108-
from(rootProject.file("README.md"))
109-
into(file("$buildDir/node_module"))
110-
}
111-
112-
val copyPackageJson by registering(Copy::class) {
113-
from(file("package.json"))
114-
into(file("$buildDir/node_module"))
115-
}
116-
117-
val unzipJar by registering(Copy::class) {
118-
val zipFile = File("$buildDir/libs", "${project.name}-js-${project.version}.jar")
119-
from(this.project.zipTree(zipFile))
120-
into("$buildDir/classes/kotlin/js/main/")
121-
}
122-
123-
val copyJS by registering {
124-
mustRunAfter("unzipJar", "copyPackageJson")
125-
doLast {
126-
val from = File("$buildDir/classes/kotlin/js/main/${rootProject.name}-${project.name}.js")
127-
val into = File("$buildDir/node_module/${project.name}.js")
128-
into.createNewFile()
129-
into.writeText(
130-
from.readText()
131-
.replace("require('firebase-kotlin-sdk-", "require('@gitlive/")
132-
// .replace("require('kotlinx-serialization-kotlinx-serialization-runtime')", "require('@gitlive/kotlinx-serialization-runtime')")
133-
)
134-
}
135-
}
136-
137-
val copySourceMap by registering(Copy::class) {
138-
from(file("$buildDir/classes/kotlin/js/main/${project.name}.js.map"))
139-
into(file("$buildDir/node_module"))
140-
}
141-
142-
val prepareForNpmPublish by registering {
143-
dependsOn(
144-
unzipJar,
145-
copyPackageJson,
146-
copySourceMap,
147-
copyReadMe,
148-
copyJS
149-
)
150-
}
151-
152-
val publishToNpm by creating(Exec::class) {
153-
workingDir("$buildDir/node_module")
154-
isIgnoreExitValue = true
155-
if(Os.isFamily(Os.FAMILY_WINDOWS)) {
156-
commandLine("cmd", "/c", "npm publish")
157-
} else {
158-
commandLine("npm", "publish")
159-
}
160-
}
161105
}
162106

163107
afterEvaluate {
164-
// create the projects node_modules if they don't exist
165-
if(!File("$buildDir/node_module").exists()) {
166-
mkdir("$buildDir/node_module")
167-
}
168108

169109
dependencies {
170110
"commonMainImplementation"("org.jetbrains.kotlinx:kotlinx-coroutines-core:1.6.4")
@@ -175,7 +115,13 @@ subprojects {
175115
"commonTestImplementation"("org.jetbrains.kotlinx:kotlinx-coroutines-core:1.6.4")
176116
"commonTestImplementation"("org.jetbrains.kotlinx:kotlinx-coroutines-test:1.6.4")
177117
if (this@afterEvaluate.name != "firebase-crashlytics") {
118+
"jvmMainApi"("dev.gitlive:firebase-java-sdk:0.1.1")
119+
"jvmMainApi"("org.jetbrains.kotlinx:kotlinx-coroutines-play-services:1.6.0") {
120+
exclude("com.google.android.gms")
121+
}
178122
"jsTestImplementation"(kotlin("test-js"))
123+
"jvmTestImplementation"(kotlin("test-junit"))
124+
"jvmTestImplementation"("junit:junit:4.13.2")
179125
}
180126
"androidAndroidTestImplementation"(kotlin("test-junit"))
181127
"androidAndroidTestImplementation"("junit:junit:4.13.2")

firebase-app/build.gradle.kts

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -50,6 +50,13 @@ kotlin {
5050
publishAllLibraryVariants()
5151
}
5252

53+
jvm {
54+
val main by compilations.getting {
55+
kotlinOptions {
56+
jvmTarget = "17"
57+
}
58+
}
59+
}
5360

5461
if (supportIosTarget) {
5562
ios()
@@ -106,6 +113,10 @@ kotlin {
106113
}
107114
}
108115

116+
val jvmMain by getting {
117+
kotlin.srcDir("src/androidMain/kotlin")
118+
}
119+
109120
if (supportIosTarget) {
110121
val iosMain by getting
111122
val iosSimulatorArm64Main by getting

firebase-app/package.json

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"name": "@gitlive/firebase-app",
3-
"version": "1.8.2",
3+
"version": "1.9.2",
44
"description": "Wrapper around firebase for usage in Kotlin Multiplatform projects",
55
"main": "firebase-app.js",
66
"scripts": {
@@ -23,7 +23,7 @@
2323
},
2424
"homepage": "https://github.com/GitLiveApp/firebase-kotlin-sdk",
2525
"dependencies": {
26-
"@gitlive/firebase-common": "1.8.2",
26+
"@gitlive/firebase-common": "1.9.2",
2727
"firebase": "9.19.1",
2828
"kotlin": "1.8.20",
2929
"kotlinx-coroutines-core": "1.6.4"
Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
/*
2+
* Copyright (c) 2020 GitLive Ltd. Use of this source code is governed by the Apache 2.0 license.
3+
*/
4+
5+
@file:JvmName("tests")
6+
package dev.gitlive.firebase
7+
8+
actual val context: Any = Unit
9+
10+
actual fun runTest(test: suspend () -> Unit) = kotlinx.coroutines.test.runTest { test() }

firebase-auth/build.gradle.kts

Lines changed: 13 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -35,7 +35,7 @@ android {
3535
getByName("main") {
3636
manifest.srcFile("src/androidMain/AndroidManifest.xml")
3737
}
38-
getByName("androidTest"){
38+
getByName("androidTest") {
3939
java.srcDir(file("src/androidAndroidTest/kotlin"))
4040
manifest.srcFile("src/androidAndroidTest/AndroidManifest.xml")
4141
}
@@ -109,6 +109,14 @@ kotlin {
109109
}
110110
}
111111

112+
jvm {
113+
val main by compilations.getting {
114+
kotlinOptions {
115+
jvmTarget = "17"
116+
}
117+
}
118+
}
119+
112120
sourceSets {
113121
all {
114122
languageSettings.apply {
@@ -132,6 +140,10 @@ kotlin {
132140
}
133141
}
134142

143+
val jvmMain by getting {
144+
kotlin.srcDir("src/androidMain/kotlin")
145+
}
146+
135147
if (supportIosTarget) {
136148
val iosMain by getting
137149
val iosSimulatorArm64Main by getting

firebase-auth/package.json

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"name": "@gitlive/firebase-auth",
3-
"version": "1.8.2",
3+
"version": "1.9.2",
44
"description": "Wrapper around firebase for usage in Kotlin Multiplatform projects",
55
"main": "firebase-auth.js",
66
"scripts": {
@@ -23,7 +23,7 @@
2323
},
2424
"homepage": "https://github.com/GitLiveApp/firebase-kotlin-sdk",
2525
"dependencies": {
26-
"@gitlive/firebase-app": "1.8.2",
26+
"@gitlive/firebase-app": "1.9.2",
2727
"firebase": "9.19.1",
2828
"kotlin": "1.8.20",
2929
"kotlinx-coroutines-core": "1.6.4"
Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
/*
2+
* Copyright (c) 2020 GitLive Ltd. Use of this source code is governed by the Apache 2.0 license.
3+
*/
4+
5+
@file:JvmName("tests")
6+
package dev.gitlive.firebase.auth
7+
8+
9+
actual val emulatorHost: String = "10.0.2.2"
10+
11+
actual val context: Any = Unit
12+
13+
actual fun runTest(test: suspend () -> Unit) = kotlinx.coroutines.test.runTest { test() }

firebase-common/build.gradle.kts

Lines changed: 28 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,10 @@ android {
2323
getByName("main") {
2424
manifest.srcFile("src/androidMain/AndroidManifest.xml")
2525
}
26-
getByName("androidTest").java.srcDir(file("src/androidAndroidTest/kotlin"))
26+
getByName("androidTest") {
27+
java.srcDir(file("src/androidAndroidTest/kotlin"))
28+
manifest.srcFile("src/androidAndroidTest/AndroidManifest.xml")
29+
}
2730
}
2831
testOptions {
2932
unitTests.apply {
@@ -46,6 +49,19 @@ kotlin {
4649
publishAllLibraryVariants()
4750
}
4851

52+
jvm {
53+
val main by compilations.getting {
54+
kotlinOptions {
55+
jvmTarget = "17"
56+
}
57+
}
58+
val test by compilations.getting {
59+
kotlinOptions {
60+
jvmTarget = "17"
61+
}
62+
}
63+
}
64+
4965
val supportIosTarget = project.property("skipIosTarget") != "true"
5066

5167
if (supportIosTarget) {
@@ -116,6 +132,17 @@ kotlin {
116132
api(npm("firebase", "9.4.1"))
117133
}
118134
}
135+
136+
val jvmMain by getting {
137+
kotlin.srcDir("src/androidMain/kotlin")
138+
}
139+
140+
val jvmTest by getting {
141+
dependencies {
142+
implementation(kotlin("test-junit"))
143+
}
144+
kotlin.srcDir("src/androidAndroidTest/kotlin")
145+
}
119146
}
120147
}
121148

firebase-common/package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"name": "@gitlive/firebase-common",
3-
"version": "1.8.2",
3+
"version": "1.9.2",
44
"description": "Wrapper around firebase for usage in Kotlin Multiplatform projects",
55
"main": "firebase-common.js",
66
"scripts": {

0 commit comments

Comments
 (0)