Hello guys, how can I remove a dependency on commo...
# multiplatform
d
Hello guys, how can I remove a dependency on commonMain for a custom sourceset?
j
How are you creating the source set and what's your use case for it? You can't remove source set dependencies once defined (at least not since 1.8.0 and it was never officially supported), but you can define custom source sets in a way that they wouldn't depend on commonMain.
d
I'm sorry, I didn't write my question correctly. I just noticed the goal was to make commonTest not dependent uppon commonMain, but with an intermediate source set in between. i.e.
Copy code
val commonClientMain by creating {
    dependsOn(commonMain)
}
val commonTest by getting {
    dependsOn(commonClientMain)
}
and now making commonTest only depend uppon commonMain indirectly. The use case is that I'm working around not successully being able to mock in commonClientTest (a custom source set, see https://kotlinlang.slack.com/archives/C0BLU9K96/p1687546043593929). It works with commonTest, so I decided to test commonClientMain there as well. It doesnt work when executing the common tests when selecting js as target, showing an error that indicates that it sees a duplicate of sources. It works when running with jvm though.
j
commonTest doesn't have a
dependsOn
relationship with commonMain, so connecting them in this way would be problematic. They are separate source set trees that have a friend relationship that allows tests to access
internal
visibility APIs. See this thread for more explanation.
d
commonTest doesn't have a dependsOn relationship with commonMain
Well, there must certainly be a dependency. When opening the module settings (right click on module -> open module settings). I can clearly see that commonTest depends upon commonMain without a dependsOn in the gradle script.
j
A source set tree hierarchy's
dependsOn
relationships between source sets is not the equivalent of a module's dependency relationships. The source set tree hierarchy allows for the `expect`/`actual` mechanism. commonTest doesn't have any tie into *commonMain*'s
expect
declarations. The relationship between commonTest and commonMain is closer to a module dependency, but has a special friend status such that commonTest can call
internal
APIs within commonMain.