I’ve multiple modules in a KMP project: some `comm...
# multiplatform
d
I’ve multiple modules in a KMP project: some
commonTest
in different modules share the same utility methods (stuff like Clock implmentation) and I’d like to make a “test utility library” module for KMP that I can add as dependencies in my
commonTest
as needed If I try to create a regular KMP project
:shared:common:test
with Android, iOS and JVM targets and add it as dependency to the
commonTest
sourceSet I get these errors:
Copy code
:shared:moduleA:iosArm64Test: Could not find :shared:common.
:shared:moduleA:iosSimulatorArm64Test: Could not find :shared:common.
:shared:moduleA:iosX64Test: Could not find :shared:common.
:shared:moduleA:jvmTest: Could not find :shared:common.
Working only in Android i could create a plain JVM project and include it as a
testImplementation
in my test to share test code between modules I’ve found this YouTrack issue which might be related but it say, quote
it has been possible to write such libraries pretty much since the beginning of Kotlin Multiplatform
Can someone provide me with a basic
build.gradle.kts
that would allow me to make a test library I can include in
commonTest
?
Does anyone know if this is possible or if I'm doing something wrong? Thanks
c
It's hard to say what's wrong in your case because you don't give any info about your setup. But yeah, you can create a module that contains only testing utilities, here's on repository that does that (
:tester
is imported into the tests of most other modules): https://gitlab.com/opensavvy/groundwork/pedestal/-/tree/e58f2f2c826bdd754f6925a6b6c390b1b70483df
d
Yeah, sorry, it's because I use convention plugins. Thank you I'll look at that module and try to find differences with mine!
What kind of information would you need from my setup?
c
Honestly, I don't even know, it could be because of so many different things. Probably the simplest solution is if you look at the repo I provided, and ask if there's something you don't understand, and we'll end up finding what's different that way
d
Thank you. It's late here. I'll look into it tomorrow morning
So what I’m seeing here is that I also need to look at https://gitlab.com/opensavvy/automation/gradle-conventions cause those are what this project uses the only things that pops out for me here are these in the kotlin.base It uses this plugin
id("org.jetbrains.kotlin.plugin.power-assert")
which I don’t think is needed it does this
Copy code
tasks.withType<Test>().configureEach {
	useJUnitPlatform()
}
which I’m not sure what is needed for and apply a java toolkit, which I don’t because I prefer to specify the target version for each module instead (but JVM shouldn’t be the problem here)
(I do not use junit 5)
c
So what I’m seeing here is that I also need to look at https://gitlab.com/opensavvy/automation/gradle-conventions cause those are what this project uses
Nothing in that repository is needed for what you're doing, there are older versions of the repository which don't use it and the
:tester
module worked well
d
There's nothing particular that repository do... Which means it's something "I" do that causes the issue? However I don't think I'm doing anything weird
So I removed all the plugin convention I had and I can still reproduce it with this simple build.gradle,kts
Copy code
plugins {
  alias(libs.plugins.kotlin.multiplatform)
  alias(libs.plugins.android.library)
}

kotlin {
  androidTarget()
  jvm()
  iosX64()
  iosArm64()
  iosSimulatorArm64()

  sourceSets {
    commonMain {
      dependencies {
        implementation(libs.kotlin.test)
        implementation(libs.kotlinx.datetime)
        implementation(libs.coroutines.core)
        implementation(libs.coroutines.test)
      }
    }

    commonTest {
      dependencies {
      }
    }

    androidMain {
      dependencies {
      }
    }

    androidInstrumentedTest {
      dependencies {
      }
    }

    iosMain {
      dependencies {
      }
    }
  }
}
plugins are: •
org.jetbrains.kotlin.multiplatform:2.1.10
com.android.library:8.10.0-alpha07
all i do with this is add it as dependency to another KMP project in the
commonTest
:shared:other:iosArm64Test: Could not find :shared:common.
Required by:
project :shared:other
where the dependency is just:
Copy code
commonTest {
      dependencies {
        implementation(":shared:common:test")
      }
    }
🤦‍♂️ i didn’t write
project()
in the dependency…. and I just kept not seeing it
c
oh wow, yeah that's it
d
I feel extremely dumb now - thanks for making me go through it again @CLOVIS - and the repository you linked is interesting I’ll look into it more cause I saw it do things that I didn’t know I could do with gradle! sorry for wasting your time!
c
no problem, I didn't do much this time! Always happy to help