Hi , i am trying to create a new source set, but its not creating directory for me for that source s...
s
Hi , i am trying to create a new source set, but its not creating directory for me for that source set. In shared build.gradle file, i am using following way to create new source set in sourceSets block:
Copy code
val nonMobileMain by creating {
     dependsOn(commonMain)
}
is there anything that i m missing? i was following this link: https://kotlinlang.org/docs/multiplatform-dsl-reference.html#custom-source-sets
m
You'll have to create the directory yourself.
val nonMobileMain by creating
only makes Gradle aware of it but does not actually create the directory
s
Ok, thanx,. let me try
Hi One question here, if i want to write some common code for desktop and web platforms, can i write that in new common sourceSet nonMobileMain and then include that source set in both , and then using that code.?
m
Yes, that should work
s
I have created one new source set
Copy code
val webDesktopCommonMain by creating {
    dependsOn(commonMain)
}
so it should include all dependencies of commonMain, right?, But it not able to resolve files and dependencies of commonMain
m
You need to connect your
webDesktopCommonMain
source set to the "leaves" source sets. Something like this:
Copy code
val commonMain by getting

        val webDesktopCommonMain by creating {
            dependsOn(commonMain)
        }

        val jsMain by getting {
            dependsOn(webDesktopCommonMain)
        }

        val jvmMain by getting {
            dependsOn(webDesktopCommonMain)
        }
(assuming web is a "js" target and desktop is a "web" target, which it should be?)
But more generally, it's pretty rare that web + desktop common code is not also common to all other platforms. Have you tried putting all your code in
commonMain
?
s
Actually for desktop and web i need scrollbar support, so as we know that will not be available in commonMain and only in desktopMain and jsMain modules , So i dont want to repeat some Composables related to scrollbar. So i am using common UI from commonMain and scrolling related main root Composables in webDesktopCommonMain, so that they will not be repeated
m
oh ok then!