Daniele Segato
03/10/2025, 11:25 AMcommonTest
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:
: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 MultiplatformCan someone provide me with a basic
build.gradle.kts
that would allow me to make a test library I can include in commonTest
?Daniele Segato
03/12/2025, 8:34 PMCLOVIS
03/12/2025, 8:45 PM:tester
is imported into the tests of most other modules): https://gitlab.com/opensavvy/groundwork/pedestal/-/tree/e58f2f2c826bdd754f6925a6b6c390b1b70483dfDaniele Segato
03/12/2025, 8:58 PMDaniele Segato
03/12/2025, 8:58 PMCLOVIS
03/12/2025, 9:00 PMDaniele Segato
03/12/2025, 10:07 PMDaniele Segato
03/13/2025, 11:23 AMid("org.jetbrains.kotlin.plugin.power-assert")
which I don’t think is needed
it does this
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)Daniele Segato
03/13/2025, 11:26 AMCLOVIS
03/13/2025, 12:50 PMSo 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 usesNothing 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 wellDaniele Segato
03/13/2025, 1:11 PMDaniele Segato
03/13/2025, 2:50 PMplugins {
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:
commonTest {
dependencies {
implementation(":shared:common:test")
}
}
Daniele Segato
03/13/2025, 2:52 PMproject()
in the dependency…. and I just kept not seeing itCLOVIS
03/13/2025, 2:56 PMDaniele Segato
03/13/2025, 2:56 PMCLOVIS
03/13/2025, 2:56 PM