https://kotlinlang.org logo
s

Shubham Singh

12/23/2022, 6:05 AM
Hi Folks! Is there a way to tell a KMP project to NOT fetch a common dependency for a particular platform For example, this dependency:
implementation("dev.icerock.moko:kswift-runtime:0.6.1")
is only available for KMM but my project supports Android, iOS, and Web as well. So can I instruct KMP to not fetch its deps for JS?
x

xxfast

12/23/2022, 7:02 AM
is js supported by the library?
s

Shubham Singh

12/23/2022, 8:11 AM
Unfortunately it doesn't
This is a library that would help me convert sealed classes into swift Enums. I'm okay with not using the library with JS since I can directly use sealed classes in the JS code. This is why I was wondering if there's a way to use KMM-only libraries in KMP as well.
j

Javier

12/23/2022, 8:55 AM
add the dependency to each source set instead of the the common one
m

Mustafa Ozhan

12/23/2022, 9:52 AM
you should reorganise your targets, you can create a new target ,lets call it
mobile
Copy code
val commonMain by getting {
            dependencies {
            }
        }


        val mobileMain by creating {
            dependencies {
                dependsOn(commonMain.get())
                // here is the mobile only dependencies
            }
        }

        val androidMain by getting {
            dependencies {
                dependsOn(mobileMain)
            }
        }

        val iosMain by getting {
            dependencies {
                dependsOn(mobileMain)
            }
        }

        val jsMain by getting {
            dependencies {
            }
        }
by this way you will be adding a middle layer between common. and android&ios
d

darkmoon_uk

12/23/2022, 10:02 AM
This is called hierarchical source-sets or HMPP.
s

Shubham Singh

12/23/2022, 11:16 AM
This works perfectly fine! Thank you folks 🙌 K This works perfectly! Thank you
5 Views