Hi Folks! Is there a way to tell a KMP project to ...
# multiplatform
s
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
is js supported by the library?
s
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
add the dependency to each source set instead of the the common one
m
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
This is called hierarchical source-sets or HMPP.
s
This works perfectly fine! Thank you folks 🙌 K This works perfectly! Thank you