Thread
#multiplatform
    g

    Guilherme Cordeiro

    1 year ago
    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:
    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

    emmanuelkehinde

    1 year ago
    Willing to know more about how this goes 👌🏽
    Arkadii Ivanov

    Arkadii Ivanov

    1 year ago
    AFAIK modules can't depend on other modules test source sets.
    t

    Tijl

    1 year ago
    just put your test utils in the main sources of a separate module, and then have test source sets depend on that module
    g

    Guilherme Cordeiro

    1 year ago
    I suspected that, but want to make sure... I'l try the suggestion of the separate module for now. Thanks!! ❤️
    russhwolf

    russhwolf

    1 year ago
    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.
    Arkadii Ivanov

    Arkadii Ivanov

    1 year ago
    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

    Guilherme Cordeiro

    1 year ago
    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! 🙇
    t

    Tijl

    1 year ago
    this is not a kmp limitation, test sourcesets are just not exportable in gradle
    g

    Guilherme Cordeiro

    1 year ago
    Nice, I didn't know that! Still so much to learn, but mistake by mistake we put the pieces together 😄 thanks again ❤️