Skip to content

Commit 740e17d

Browse files
authored
Merge pull request #43 from yml-org/feature/CM-1212/add-jvm-target
Feature/cm 1212/add jvm target
2 parents 5e98d05 + 393dbf6 commit 740e17d

File tree

10 files changed

+89
-102
lines changed

10 files changed

+89
-102
lines changed

.github/workflows/main-ci.yml

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,6 @@ on:
44
push:
55
branches: [ "main" ]
66
pull_request:
7-
branches: '*'
87
workflow_dispatch:
98

109
env:

.github/workflows/publish.yml

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -31,11 +31,11 @@ jobs:
3131
run: chmod +x gradlew
3232

3333
- name: Publish to Repository
34-
run: ./gradlew :ychat:clean publishReleasePublicationToYChatRepository
34+
run: ./gradlew :ychat:clean publish
3535

3636
env:
37-
MAVEN_USERNAME: ${{ secrets.MAVEN_USERNAME }}
38-
MAVEN_PASSWORD: ${{ secrets.MAVEN_PASSWORD}}
39-
MEMORY_KEY: ${{ secrets.MEMORY_KEY}}
40-
SIGNINGKEY: ${{ secrets.SIGNINGKEY}}
41-
SIGNINGPASSWORD: ${{ secrets.SIGNINGPASSWORD}}
37+
ORG_GRADLE_PROJECT_mavenCentralUsername: ${{ secrets.MAVEN_USERNAME }}
38+
ORG_GRADLE_PROJECT_mavenCentralPassword: ${{ secrets.MAVEN_PASSWORD}}
39+
ORG_GRADLE_PROJECT_signingInMemoryKey: ${{ secrets.MEMORY_KEY}}
40+
ORG_GRADLE_PROJECT_signingInMemoryKeyId: ${{ secrets.SIGNINGKEY}}
41+
ORG_GRADLE_PROJECT_signingInMemoryKeyPassword: ${{ secrets.SIGNINGPASSWORD}}

build.gradle.kts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@ plugins {
22
//trick: for the same plugin versions in all sub-modules
33
id("com.android.application").version(Versions.GRADLE_PLUGIN).apply(false)
44
id("com.android.library").version(Versions.GRADLE_PLUGIN).apply(false)
5+
id("com.vanniktech.maven.publish").version(Versions.PUBLISH_PLUGIN).apply(false)
56
id("io.gitlab.arturbosch.detekt").version(Versions.DETEKT_PLUGIN).apply(false)
67
id("org.jlleitschuh.gradle.ktlint").version(Versions.KTLINT_PLUGIN).apply(false)
78
id("org.jetbrains.kotlinx.kover").version(Versions.KOVER_PLUGIN).apply(false)

buildSrc/src/main/kotlin/Dependencies.kt

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,10 @@
11
object Versions {
22
const val GRADLE_PLUGIN = "7.3.0"
3-
const val DOKKA_PLUGIN = "1.7.20"
43
const val SPM_PLUGIN = "2.0.3"
54
const val DETEKT_PLUGIN = "1.22.0"
65
const val KTLINT_PLUGIN = "11.0.0"
76
const val KOVER_PLUGIN = "0.6.1"
7+
const val PUBLISH_PLUGIN = "0.24.0"
88
const val KOTLIN = "1.7.20"
99
const val COMPOSE = "1.3.3"
1010
const val COMPOSE_FOUNDATION = "1.3.1"
@@ -14,7 +14,8 @@ object Versions {
1414
const val KTOR = "2.2.2"
1515
const val KOIN = "3.2.0"
1616
const val MATERIAL_DESIGN = "1.6.1"
17-
const val MOCKK = "1.12.3"
17+
const val MOCKK = "1.13.4"
18+
const val MOCKK_COMMON = "1.12.5"
1819
}
1920

2021
object Dependencies {
@@ -26,6 +27,7 @@ object Dependencies {
2627
const val KTOR_LOGGING = "io.ktor:ktor-client-logging:${Versions.KTOR}"
2728
const val KTOR_ANDROID = "io.ktor:ktor-client-android:${Versions.KTOR}"
2829
const val KTOR_IOS = "io.ktor:ktor-client-ios:${Versions.KTOR}"
30+
const val KTOR_JAVA = "io.ktor:ktor-client-java:${Versions.KTOR}"
2931
}
3032

3133
object DI {
@@ -47,8 +49,9 @@ object Dependencies {
4749
}
4850

4951
object Test {
50-
const val MOCKK_COMMON = "io.mockk:mockk-common:${Versions.MOCKK}"
52+
const val MOCKK_COMMON = "io.mockk:mockk-common:${Versions.MOCKK_COMMON}"
5153
const val MOCKK = "io.mockk:mockk:${Versions.MOCKK}"
54+
const val MOCKK_JVM = "io.mockk:mockk-jvm:${Versions.MOCKK}"
5255
const val KTOR = "io.ktor:ktor-client-mock:${Versions.KTOR}"
5356
const val KOIN = "io.insert-koin:koin-test:${Versions.KOIN}"
5457
}

buildSrc/src/main/kotlin/spm-tasks.gradle.kts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -5,8 +5,8 @@ tasks.register("checkSwiftPackageVersion") {
55
group = "Multiplatform-swift-package"
66
description = "Checks if the Swift package has the updated version by comparing it with the current library version."
77
doLast {
8-
val iosLibraryName = properties["library.ios.name"]
9-
val libraryVersion = properties["library.version"]
8+
val iosLibraryName = properties["IOS_NAME"]
9+
val libraryVersion = properties["VERSION_NAME"]
1010
val iosPackage = "$iosLibraryName-$libraryVersion.zip"
1111
val filePath = File(rootProject.rootDir, iosPackage)
1212
if (!filePath.exists()) {

gradle.properties

Lines changed: 25 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,32 @@
1-
#Kotlin
1+
# Kotlin
22
kotlin.code.style=official
33

4-
#Android
4+
# Android
55
android.useAndroidX=true
66
android.nonTransitiveRClass=true
77

8-
#MPP
8+
# MPP
99
kotlin.mpp.enableCInteropCommonization=true
1010

11-
library.version=1.0.0
12-
library.ios.name=YChat
11+
# Lib
12+
GROUP=co.yml
13+
POM_ARTIFACT_ID=ychat
14+
VERSION_NAME=1.0.0
15+
IOS_NAME=YChat
16+
17+
# OSS
18+
SONATYPE_HOST=S01
19+
RELEASE_SIGNING_ENABLED=true
20+
21+
# POM
22+
POM_NAME=YChat
23+
POM_DESCRIPTION=YChat SDK is kotlin multiplatform library for chat gpt apis.
24+
POM_URL=https://github.com/yml-org/ychat
25+
26+
POM_LICENCE_NAME=The Apache License, Version 2.0
27+
POM_LICENCE_URL=http://www.apache.org/licenses/LICENSE-2.0.txt
28+
POM_LICENCE_DIST=repo
29+
30+
POM_SCM_URL=https://github.com/yml-org/ychat
31+
POM_SCM_CONNECTION=scm:git:git://github.com/yml-org/ychat.git
32+
POM_SCM_DEV_CONNECTION=scm:git:ssh://[email protected]:yml-org/ychat.git

ychat/build.gradle.kts

Lines changed: 29 additions & 81 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,9 @@
11
plugins {
22
kotlin("multiplatform")
33
kotlin("plugin.serialization").version(Versions.KOTLIN)
4-
id("org.jetbrains.dokka").version(Versions.DOKKA_PLUGIN)
54
id("com.chromaticnoise.multiplatform-swiftpackage").version(Versions.SPM_PLUGIN)
5+
id("com.vanniktech.maven.publish")
66
id("com.android.library")
7-
id("maven-publish")
8-
id("signing")
97
id("io.gitlab.arturbosch.detekt")
108
id("org.jlleitschuh.gradle.ktlint")
119
id("org.jetbrains.kotlinx.kover")
@@ -24,8 +22,8 @@ kover {
2422
}
2523
}
2624

27-
val iosLibraryName = properties["library.ios.name"].toString()
28-
version = properties["library.version"].toString()
25+
val iosLibraryName = properties["IOS_NAME"].toString()
26+
version = properties["VERSION_NAME"].toString()
2927

3028
multiplatformSwiftPackage {
3129
packageName(iosLibraryName)
@@ -38,7 +36,7 @@ multiplatformSwiftPackage {
3836

3937
kotlin {
4038
android()
41-
39+
jvm()
4240
listOf(
4341
iosX64(),
4442
iosArm64(),
@@ -98,6 +96,16 @@ kotlin {
9896
iosArm64Test.dependsOn(this)
9997
iosSimulatorArm64Test.dependsOn(this)
10098
}
99+
val jvmMain by getting {
100+
dependencies {
101+
implementation(Dependencies.Network.KTOR_JAVA)
102+
}
103+
}
104+
val jvmTest by getting {
105+
dependencies {
106+
implementation(Dependencies.Test.MOCKK_JVM)
107+
}
108+
}
101109
}
102110
}
103111

@@ -110,84 +118,24 @@ android {
110118
}
111119
}
112120

113-
val dokkaOutputDir = "$buildDir/dokka"
114-
115-
tasks.dokkaHtml {
116-
outputDirectory.set(file(dokkaOutputDir))
117-
}
118-
119-
val deleteDokkaOutputDir by tasks.register<Delete>("deleteDokkaOutputDirectory") {
120-
delete(dokkaOutputDir)
121-
}
122-
val javadocJar = tasks.register<Jar>("javadocJar") {
123-
dependsOn(deleteDokkaOutputDir, tasks.dokkaHtml)
124-
archiveClassifier.set("javadoc")
125-
from(dokkaOutputDir)
126-
}
127-
128-
publishing {
129-
repositories {
130-
maven {
131-
name = "YChat"
132-
setUrl("https://s01.oss.sonatype.org/service/local/staging/deploy/maven2")
133-
credentials {
134-
username = project.findProperty("mavenCentralUsername")?.toString() ?: System.getenv("MAVEN_USERNAME")
135-
password = project.findProperty("mavenCentralPassword")?.toString() ?: System.getenv("MAVEN_PASSWORD")
121+
mavenPublishing {
122+
pom {
123+
developers {
124+
developer {
125+
id.set("osugikoji")
126+
name.set("Koji Osugi")
127+
url.set("https://github.com/osugikoji")
136128
}
137-
}
138-
}
139-
publications {
140-
register<MavenPublication>("release") {
141-
groupId = "co.yml"
142-
artifactId = "ychat"
143-
version = properties["library.version"].toString()
144-
afterEvaluate {
145-
from(components["release"])
129+
developer {
130+
id.set("renatoarg")
131+
name.set("Renato Goncalves")
132+
url.set("https://github.com/renatoarg")
146133
}
147-
artifact(javadocJar)
148-
pom {
149-
name.set("YChat")
150-
description.set("YChat SDK is kotlin multiplatform library for chat gpt apis.")
151-
url.set("https://github.com/yml-org/ychat")
152-
licenses {
153-
license {
154-
name.set("The Apache License, Version 2.0")
155-
url.set("http://www.apache.org/licenses/LICENSE-2.0.txt")
156-
distribution.set("http://www.apache.org/licenses/LICENSE-2.0.txt")
157-
}
158-
}
159-
developers {
160-
developer {
161-
id.set("osugikoji")
162-
name.set("Koji Osugi")
163-
url.set("https://github.com/osugikoji")
164-
}
165-
developer {
166-
id.set("renatoarg")
167-
name.set("Renato Goncalves")
168-
url.set("https://github.com/renatoarg")
169-
}
170-
developer {
171-
id.set("kikoso")
172-
name.set("Enrique López Mañas")
173-
url.set("https://github.com/kikoso")
174-
}
175-
}
176-
scm {
177-
url.set("https://github.com/yml-org/ychat")
178-
connection.set("scm:git:git://github.com/yml-org/ychat.git")
179-
developerConnection.set("scm:git:ssh://[email protected]:yml-org/ychat.git")
180-
}
134+
developer {
135+
id.set("kikoso")
136+
name.set("Enrique López Mañas")
137+
url.set("https://github.com/kikoso")
181138
}
182139
}
183140
}
184141
}
185-
186-
signing {
187-
useInMemoryPgpKeys(
188-
project.findProperty("signing.keyId")?.toString() ?: System.getenv("SIGNINGKEY"),
189-
project.findProperty("signing.InMemoryKey")?.toString() ?: System.getenv("MEMORY_KEY"),
190-
project.findProperty("signing.password")?.toString() ?: System.getenv("SIGNINGPASSWORD")
191-
)
192-
sign(publishing.publications)
193-
}

ychat/src/commonMain/kotlin/co/yml/ychat/di/module/LibraryModule.kt

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@ import co.yml.ychat.di.provider.NetworkProvider
88
import co.yml.ychat.domain.usecases.CompletionUseCase
99
import co.yml.ychat.entrypoint.features.Completion
1010
import co.yml.ychat.entrypoint.impl.CompletionImpl
11+
import kotlinx.coroutines.Dispatchers
1112
import org.koin.core.module.Module
1213
import org.koin.dsl.module
1314

@@ -17,7 +18,7 @@ internal class LibraryModule(private val apiKey: String) {
1718
entrypointModule + domainModule + dataModule + platformModule()
1819

1920
private val entrypointModule = module {
20-
factory<Completion> { CompletionImpl(get()) }
21+
factory<Completion> { CompletionImpl(Dispatchers.Default, get()) }
2122
}
2223

2324
private val domainModule = module {

ychat/src/commonMain/kotlin/co/yml/ychat/entrypoint/impl/CompletionImpl.kt

Lines changed: 10 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -4,10 +4,17 @@ import co.yml.ychat.YChat
44
import co.yml.ychat.domain.model.CompletionParams
55
import co.yml.ychat.domain.usecases.CompletionUseCase
66
import co.yml.ychat.entrypoint.features.Completion
7-
import kotlinx.coroutines.MainScope
7+
import kotlinx.coroutines.CoroutineDispatcher
8+
import kotlinx.coroutines.CoroutineScope
9+
import kotlinx.coroutines.SupervisorJob
810
import kotlinx.coroutines.launch
911

10-
internal class CompletionImpl(private val completionUseCase: CompletionUseCase) : Completion {
12+
internal class CompletionImpl(
13+
private val dispatcher: CoroutineDispatcher,
14+
private val completionUseCase: CompletionUseCase
15+
) : Completion {
16+
17+
private val scope by lazy { CoroutineScope(SupervisorJob() + dispatcher) }
1118

1219
private var params: CompletionParams = CompletionParams()
1320

@@ -50,7 +57,7 @@ internal class CompletionImpl(private val completionUseCase: CompletionUseCase)
5057
}
5158

5259
override fun execute(callback: YChat.Callback<String>) {
53-
MainScope().launch {
60+
scope.launch {
5461
runCatching { execute() }
5562
.onSuccess { callback.onSuccess(it) }
5663
.onFailure { callback.onError(it) }
Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
package co.yml.ychat.di.module
2+
3+
import io.ktor.client.engine.java.Java
4+
import org.koin.dsl.module
5+
6+
internal actual fun platformModule() = module {
7+
single { Java.create() }
8+
}

0 commit comments

Comments
 (0)