hi, in a kotlin/multiplatform project, I'm encount...
# gradle
s
hi, in a kotlin/multiplatform project, I'm encountering the following error
Copy code
w: Kotlin Source Set 'commonBenchmarks' can't depend on 'commonMain' as they are from different Source Set Trees.
Please remove this dependency edge.
my gradle buildscript looks roughly like this (this is not the exact buildscript, just a rough recreation with only the relevant bits)
Copy code
plugins {
    kotlin("multiplatform") version "2.1.10"
    kotlin("plugin.allopen")

    id("org.jetbrains.kotlinx.benchmark")
}

allOpen {
    annotation("org.openjdk.jmh.annotations.State") // Make jmh happy
}

kotlin {
    jvm {
        val benchmarks by compilations.creating {
            associateWith(this@jvm.compilations["main"])
        }
    }

    sourceSets {
        val commonBenchmarks by creating {
            dependsOn(commonMain.get())
            dependencies {
                implementation(libs.kotlinx.benchmark.runtime)
            }
        }
        val jvmBenchmarks by getting {
            dependsOn(commonBenchmarks)
        }
    }
}

benchmark {
    configurations {
        named("main") {
            reportFormat = "json"
            warmups = 5
            iterations = 5
            iterationTime = 5
            iterationTimeUnit = "s"
        }
    }
    targets {
        register("jvmBenchmarks") {
            this as JvmBenchmarkTarget
            jmhVersion = "1.37"
        }
    }
}
does anyone know how to solve this issue?
t
Better to use hierarchy template to configure source sets structure in your KMP project, e.g.:
Copy code
kotlin {
    applyDefaultHierarchyTemplate {
        common {
            group("commonJvm") {
                withJvm()
                withAndroid()
            }
        }
    }
}
s
I'm not sure hierarchy templates apply here, as the
jvmMain
source set (or any other such leaf source set, asside from the other new source set I introduced,
jvmBenchmarks
) does not depend on the
commonBenchmarks
source set.
e
I have something similar working in https://github.com/ephemient/aoc2024/blob/main/kt/aoc2024-exe/build.gradle.kts; I think you may just need
Copy code
kotlin {
    applyDefaultHierarchyTemplate {
        withSourceSetTree(KotlinSourceSetTree("benchmarks"))
    }
}
instead of
dependsOn
s
interesting, I'll give that a try.