Skip to content

Commit

Permalink
fix(example): add Ksp Ktorfit plugin to test sourceSets (#404)
Browse files Browse the repository at this point in the history
* fix(example): add Ksp Ktorfit plugin to test sourceSets, fix commonTest to support all platforms
  • Loading branch information
xiaobailong24 authored Aug 31, 2023
1 parent 498bd91 commit dfa15d7
Show file tree
Hide file tree
Showing 6 changed files with 65 additions and 63 deletions.
1 change: 0 additions & 1 deletion example/MultiplatformExample/gradle.properties
Original file line number Diff line number Diff line change
Expand Up @@ -6,5 +6,4 @@ kotlin.code.style=official
android.useAndroidX=true
#MPP
kotlin.mpp.enableCInteropCommonization=true
kotlin.native.binary.memoryModel=experimental
kotlin.mpp.androidSourceSetLayoutVersion=2
88 changes: 29 additions & 59 deletions example/MultiplatformExample/shared/build.gradle.kts
Original file line number Diff line number Diff line change
Expand Up @@ -11,29 +11,20 @@ version = "1.0"
val ktorVersion = "2.3.3"
val ktorfitVersion = "1.6.0"

configure<de.jensklingenberg.ktorfit.gradle.KtorfitGradleConfiguration> {
ktorfit {
version = ktorfitVersion
logging = true
}

tasks.withType<org.jetbrains.kotlin.gradle.tasks.KotlinCompile> {
kotlinOptions.jvmTarget = "1.8"
}

java {
toolchain {
languageVersion.set(JavaLanguageVersion.of(8))
}
}
kotlin {
android()
jvmToolchain(8)
targetHierarchy.default()

jvm()
androidTarget()
iosX64()
iosArm64()
iosSimulatorArm64()
jvm(){
compilations.all {
kotlinOptions.jvmTarget = "1.8"
}
}
macosX64()
js(IR) {
this.nodejs()
Expand Down Expand Up @@ -67,43 +58,11 @@ kotlin {
implementation(kotlin("test"))
}
}
val androidMain by getting {
dependencies {
//implementation("io.ktor:ktor-client-cio-jvm:$ktorVersion")
}
}
val jvmMain by getting {
dependencies {


}
}
val jsMain by getting {
dependencies {

}
}
val iosX64Main by getting
val iosArm64Main by getting
val iosSimulatorArm64Main by getting
val iosMain by creating {
dependsOn(commonMain)
iosX64Main.dependsOn(this)
iosArm64Main.dependsOn(this)
iosSimulatorArm64Main.dependsOn(this)
dependencies{
// implementation("io.ktor:ktor-client-ios:$ktorVersion")
}
}
val iosX64Test by getting
val iosArm64Test by getting
val iosSimulatorArm64Test by getting
val iosTest by creating {
dependsOn(commonTest)
iosX64Test.dependsOn(this)
iosArm64Test.dependsOn(this)
iosSimulatorArm64Test.dependsOn(this)
}
val androidMain by getting
val jvmMain by getting
val jsMain by getting
val iosMain by getting
val macosX64Main by getting
}
}

Expand All @@ -117,11 +76,22 @@ android {
}

dependencies {
add("kspCommonMainMetadata", "de.jensklingenberg.ktorfit:ktorfit-ksp:$ktorfitVersion")
add("kspJvm", "de.jensklingenberg.ktorfit:ktorfit-ksp:$ktorfitVersion")
add("kspAndroid", "de.jensklingenberg.ktorfit:ktorfit-ksp:$ktorfitVersion")
add("kspIosX64", "de.jensklingenberg.ktorfit:ktorfit-ksp:$ktorfitVersion")
add("kspJs", "de.jensklingenberg.ktorfit:ktorfit-ksp:$ktorfitVersion")
add("kspIosSimulatorArm64", "de.jensklingenberg.ktorfit:ktorfit-ksp:$ktorfitVersion")
with("de.jensklingenberg.ktorfit:ktorfit-ksp:$ktorfitVersion") {
add("kspCommonMainMetadata", this)
add("kspJvm", this)
add("kspJvmTest", this)
add("kspAndroid", this)
add("kspAndroidTest", this)
add("kspIosX64", this)
add("kspIosX64Test", this)
add("kspIosArm64", this)
add("kspIosArm64Test", this)
add("kspIosSimulatorArm64", this)
add("kspIosSimulatorArm64Test", this)
add("kspMacosX64", this)
add("kspMacosX64Test", this)
add("kspJs", this)
add("kspJsTest", this)
}
}

Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
package com.example.ktorfittest

import kotlinx.coroutines.GlobalScope
import kotlinx.coroutines.launch
import kotlin.test.Test
import kotlin.test.assertEquals

class KtorfitTest {
@Test
fun test() {
GlobalScope.launch {
ktorfit.create<TestApi>()
.getPersonByIdResponse(3)
.collect {
assertEquals(it.name, "R2-D2")
}
}
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
package com.example.ktorfittest

import de.jensklingenberg.ktorfit.http.GET
import de.jensklingenberg.ktorfit.http.Path
import kotlinx.coroutines.flow.Flow

interface TestApi {
companion object {
const val baseUrl = "https://swapi.dev/api/"
}

@GET("people/{id}/")
suspend fun getPersonByIdResponse(@Path("id") peopleId: Int): Flow<Person>
}

Original file line number Diff line number Diff line change
Expand Up @@ -2,5 +2,5 @@ package com.example.ktorfittest

actual class Platform actual constructor() {
actual val platform: String
get() = "JVM"
get() = "JS"
}
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
package com.example.ktorfittest

import platform.UIKit.UIDevice

actual class Platform actual constructor() {
actual val platform: String = UIDevice.currentDevice.systemName() + " " + UIDevice.currentDevice.systemVersion
actual val platform: String = "macOS"
}

0 comments on commit dfa15d7

Please sign in to comment.