Foso / Ktorfit

HTTP client generator / KSP plugin for Kotlin Multiplatform (Android, iOS, Js, Jvm, Native, WasmJs)) using KSP and Ktor clients inspired by Retrofit https://foso.github.io/Ktorfit
https://foso.github.io/Ktorfit
Apache License 2.0
1.61k stars 42 forks source link

Ktorfit Gradle Plugin not compatible with Android Multiplatform Library plugin #638

Open Sanlorng opened 3 months ago

Sanlorng commented 3 months ago

Ktorfit version

2.0.1

What happened and how can we reproduce this issue?

the ktorfit gradle plugin will add ksp depedency named 'kspAndroidTest' automatically, but it seems not exist when android multiplatform library plugin(com.android.kotlin.multiplatform.library) applied, when i change android multiplatform library to android library plugin(com.android.library), the ktorfit gradle plugin works normally. image

What did you expect to happen?

work with android mutiplatform library plugin

Is there anything else we need to know about?

No response

Foso commented 3 months ago

Hi, do you know if there is any documentation about the android multiplatform library plugin ?

Sanlorng commented 3 months ago

Hi, do you know if there is any documentation about the android multiplatform library plugin ?

According to the official documentation of KSP, we should declare symbol processors based on the compilation target or source code directory. In Android Multiplatform Library plugin, the androidTestsource code directory no longer exists. Instead, there are two configurable test source code directories: one for androidTestWithJvm(default name: AndroidTestWithJvm) and another for androidTestWithDevice(default name: AndroidTestWithDevice). These two types of directories are only created in the KotlinExtension.sourceSets when explicitly declared by the user, and their names can be modified. You can find more details in the official Android Multiplatform Library plugin documentation. In the Ktorfit Gradle Plugin, it seems that symbol processors are declared based on the compilation target, and for the test part, you may need to handle it separately by iterating through the SourceSets or allowing users to declare it themselves. This flexibility could enhance the applicability of the Ktorfit Gradle Plugin.

Foso commented 2 months ago

Thank you very much for the informations! I think i will add a check if a sourceset with "Test" exist and only then apply KSP

Foso commented 2 months ago

Hi with version 2.1.0 i added the check for "test". It should not lead to compilation error anymore, but you would have to add ksp manually for e.g. the androidTestWithDevice task