Karan Sharma
01/03/2025, 1:23 PM:core:x
has (commonMain, commonTest)
• :data
It depends on corex and has (commonMain, commonTest)
A test in datacommonTest needs a fake impl of class from corex module. Where should I put the fake implementation?
1. In corex:commonMain ? - It will be included in binary, so No
2. In corex:commonTest ? - Unable to access another module's commonTest
3. Somewhere else?Michael Krussel
01/03/2025, 1:30 PM:core:x-test-support
library for it and put the code in commonMain
of that module. Then the test source set for :data
depended on the :core:x-test-support
.CLOVIS
01/03/2025, 4:26 PMephemient
01/03/2025, 6:20 PMNick
01/04/2025, 4:11 AMinternal
in my :core module. so i really need a test fixture (i think) to expose APIs that work with these internal types.ephemient
01/04/2025, 7:01 AM// producer/build.gradle.kts
import org.jetbrains.kotlin.gradle.plugin.KotlinPlatformType
import org.jetbrains.kotlin.gradle.plugin.KotlinSourceSetTree
import org.jetbrains.kotlin.gradle.plugin.mpp.KotlinMetadataTarget
import org.jetbrains.kotlin.gradle.plugin.usesPlatformOf
plugins {
kotlin("multiplatform")
}
kotlin {
targets.all target@{
if (this is KotlinMetadataTarget) return@target
val name = "${name}TestFixtures"
compilations.create("testFixtures") {
associateWith(this@target.compilations.getByName("main"))
this@target.compilations.getByName("test").associateWith(this)
configurations.consumable("${name}ApiElements") {
attributes {
attribute(Usage.USAGE_ATTRIBUTE, objects.named(if (platformType == KotlinPlatformType.jvm) "java-api-jars" else "kotlin-api"))
attribute(Category.CATEGORY_ATTRIBUTE, objects.named(Category.LIBRARY))
}
extendsFrom(configurations.getByName(apiConfigurationName))
usesPlatformOf(this@target)
outgoing {
capability("$group:${project.name}-test-fixtures:$version")
for (output in output.allOutputs) artifact(output) { builtBy(compileTaskProvider) }
}
}
configurations.consumable("${name}RuntimeElements") {
attributes {
attribute(Usage.USAGE_ATTRIBUTE, objects.named(if (platformType == KotlinPlatformType.jvm) "java-runtime-jars" else "kotlin-runtime"))
attribute(Category.CATEGORY_ATTRIBUTE, objects.named(Category.LIBRARY))
}
extendsFrom(configurations.getByName(implementationConfigurationName))
extendsFrom(configurations.getByName(runtimeOnlyConfigurationName))
usesPlatformOf(this@target)
outgoing {
capability("$group:${project.name}-test-fixtures:$version")
for (output in output.allOutputs) artifact(output) { builtBy(compileTaskProvider) }
}
}
}
}
applyDefaultHierarchyTemplate {
withSourceSetTree(KotlinSourceSetTree("testFixtures"))
}
}
// consumer/build.gradle.kts
plugins {
kotlin("multiplatform")
}
kotlin {
sourceSets {
commonTest {
dependencies {
implementation(project(":producer")) {
capabilities {
requireCapability("$group:$name-test-fixtures:$version")
}
}
}
}
}
}
ephemient
01/04/2025, 7:05 AMephemient
01/04/2025, 7:13 AMNick
01/04/2025, 6:20 PMNick
01/11/2025, 5:03 PMephemient
01/11/2025, 7:06 PMNick
01/11/2025, 8:43 PMNick
01/12/2025, 6:04 AMplugins {
kotlin("multiplatform")
}
kotlin {
...
applyDefaultHierarchyTemplate()
sourceSets {
...
commonMain.dependencies {
...
}
commonTest.dependencies {
...
}
val jsCommon by creating { dependsOn(commonMain.get()) }
jsMain.get().dependsOn(jsCommon)
jvmTest.dependencies {
...
}
val wasmJsMain by getting {
dependsOn(jsCommon)
}
}
targets.all target@{
if (this is KotlinMetadataTarget) return@target
val name = "${name}TestFixtures"
compilations.create("testFixtures") {
associateWith(this@target.compilations.getByName("main"))
this@target.compilations.getByName("test").associateWith(this)
configurations.consumable("${name}ApiElements") {
attributes {
attribute(Usage.USAGE_ATTRIBUTE, objects.named(if (platformType == KotlinPlatformType.jvm) "java-api-jars" else "kotlin-api"))
attribute(Category.CATEGORY_ATTRIBUTE, objects.named(Category.LIBRARY))
}
extendsFrom(configurations.getByName(apiConfigurationName))
usesPlatformOf(this@target)
outgoing {
capability("$group:${project.name}-test-fixtures:$version")
for (output in output.allOutputs) artifact(output) { builtBy(compileTaskProvider) }
}
}
configurations.consumable("${name}RuntimeElements") {
attributes {
attribute(Usage.USAGE_ATTRIBUTE, objects.named(if (platformType == KotlinPlatformType.jvm) "java-runtime-jars" else "kotlin-runtime"))
attribute(Category.CATEGORY_ATTRIBUTE, objects.named(Category.LIBRARY))
}
extendsFrom(configurations.getByName(implementationConfigurationName))
extendsFrom(configurations.getByName(runtimeOnlyConfigurationName ))
usesPlatformOf(this@target)
outgoing {
capability("$group:${project.name}-test-fixtures:$version")
for (output in output.allOutputs) artifact(output) { builtBy(compileTaskProvider) }
}
}
}
}
applyDefaultHierarchyTemplate {
withSourceSetTree(KotlinSourceSetTree("testFixtures"))
}
}
controls (build.gradle.kts)
plugins {
kotlin("multiplatform")
}
kotlin {
...
sourceSets {
...
commonMain.dependencies {
api(projects.core)
...
}
commonTest.dependencies {
implementation(kotlin("test-common"))
implementation(kotlin("test-annotations-common"))
}
jvmTest.dependencies {
implementation(kotlin("test-junit"))
implementation(libs.bundles.test.libs)
implementation(projects.core) {
capabilities {
requireCapability("$group:$name-test-fixtures:$version")
}
}
}
}
}
A problem was found with the configuration of task ':controls:jvmTest' (type 'KotlinJvmTest').
- Gradle detected a problem with the following location: '<...>/Core/build/processedResources/jvm/testFixtures'.
Reason: Task ':controls:jvmTest' uses this output of task ':core:jvmTestFixturesProcessResources' without declaring an explicit or implicit dependency. This can lead to incorrect results being produced, depending on what order the tasks are executed.
Possible solutions:
1. Declare task ':core:jvmTestFixturesProcessResources' as an input of ':controls:jvmTest'.
2. Declare an explicit dependency on ':core:jvmTestFixturesProcessResources' from ':controls:jvmTest' using Task#dependsOn.
3. Declare an explicit dependency on ':core:jvmTestFixturesProcessResources' from ':controls:jvmTest' using Task#mustRunAfter.
Nick
01/12/2025, 8:47 AMparallel
gradle flag.ephemient
01/12/2025, 2:38 PMephemient
01/12/2025, 2:45 PMallOutputs
compilations.all compilation@{
// ...
for (classesDir in output.classesDirs) artifact(classesDir) { builtBy(compileTaskProvider) }
if (this@compilation is KotlinJvmCompilation) {
artifact(output.resourcesDir) { builtBy(processResourcesTaskName) }
}
(not at computer now, can't check)Nick
01/12/2025, 11:30 PM// ...
outgoing {
capability("$group:${project.name}-test-fixtures:$version")
this@target.compilations.all compilation@{
for (classesDir in output.classesDirs) artifact(classesDir) { builtBy(compileTaskProvider) }
if (this@compilation is KotlinJvmCompilation) {
artifact(output.resourcesDir) { builtBy(processResourcesTaskName) }
}
}
}