Hello! Maybe I am doing something wrong without re...
# multiplatform
g
Hello! Maybe I am doing something wrong without realizing, but I am struggling to share code between different KMM modules... If I have: 1. A base KMM module, with code both on
commonMain
and
commonTest
that I want to share (like frameworks, contracts, test utilities, etc) 2. Several other independently built modules, depending on the base module What is the proper way to add the base module on the dependencies of the child modules? Inside the
sourceSets
block, for both
commonMain
and
commonTest
? Can I access classes defined on the base module
commonTest
inside a child module
commonTest
?
I tried to add like this:
Copy code
sourceSets {
    val commonMain by getting {
        dependencies {
            api(project(":base"))
        }
    }
    val commonTest by getting {
        dependencies {
            api(project(":base"))
        }
    }
}
but although I can import classes from base
commonTest
on the child module
commonTest
, I get an
Unresolved reference
error when compiling ๐Ÿ˜•
Thanks in advance for any suggestions or corrections ๐Ÿ™
e
Willing to know more about how this goes ๐Ÿ‘Œ๐Ÿฝ
a
AFAIK modules can't depend on other modules test source sets.
t
just put your test utils in the main sources of a separate module, and then have test source sets depend on that module
g
I suspected that, but want to make sure... I'l try the suggestion of the separate module for now. Thanks!! โค๏ธ
r
I've been using the separate module trick for a couple years now. It has occasionally led to tooling issues (I think it was around 1.3.40 I couldn't build due to some weird compiler/gradle plugin bugs) but for the most part it's worked well.
a
The only issue with separate module for test utils is that the code is treated as production, not as test. E.g. detekt may not ignore some relaxed checks, IDEA shows warnings about test function names, etc.
g
I see... I agree it's not ideal, but acceptable for now as kmp is still in early stages of development... I'll bear the limitations on mind, thanks for all the orientations! ๐Ÿ™‡
๐Ÿ‘ 1
t
this is not a kmp limitation, test sourcesets are just not exportable in gradle
โž• 1
๐Ÿ™‡ 1
today i learned 1
g
Nice, I didn't know that! Still so much to learn, but mistake by mistake we put the pieces together ๐Ÿ˜„ thanks again โค๏ธ