I have a multi-platform Kotlin project, which contains multiple modules (subprojects). The Building Multiplatform Projects with Gradle documentation of Kotlin clearly shows how to set up project dependencies between modules:
kotlin {
sourceSets {
commonMain {
dependencies {
// All of the compilations that include source set 'commonMain'
// will get this dependency resolved to a compatible target, if any:
api project(':foo-lib')
}
}
}
}
The problem I am facing now is that although this documents how to add a dependency from one module (all of its target platforms) to another module (its corresponding target platforms), it does not clarify how to add a dependency to the test sources of another module.
I would expect this to be a fairly common use case. For example, one of the reasons I want to do this is that my test sources of module A contain stub classes. Module B depends on module A, including the class definitions for which test stubs are provided in the test sources of module A. Thus, it is not unexpected that tests of module B might want to reuse those test stubs defined in the test sources of module A.
A common recommendation in multi-project builds is to move such test sources to yet another module, but this seems unnecessary to me. Solutions which in my opinion are cleaner exist for normal multi-project builds, but I can't figure out how to configure the equivalent of this in a multi-platform multi-project Kotlin build which also relies on the Kotlin Gradle DSL demonstrated in the code above.