Test dependency in a Kotlin Multiplatform Gradle Multi-Project?

I have a Kotlin Multiplatform Gradle Multi-Project with two subprojects:

  • yass2-core: base project
  • yass2-tail: depends on yass2-core

versions: Gradle 6.3, Kotlin 1.3.71, Java 11.0.6

build.gradle.kts:

val coreProject = project("yass2-core") {
    kotlin {
        sourceSets {
            val commonMain by getting {
                dependencies {
                    api(kotlin("stdlib-common"))
                }
            }
            val commonTest by getting {
                dependencies {
                }
            }
        }
    }
}

project("yass2-tail") {
    kotlin {
        sourceSets {
            val commonMain by getting {
                dependencies {
                    api(coreProject)
                }
            }
            val commonTest by getting {
                dependencies {
                    implementation(project(":yass2-core", "commonTestImplementation"))
                }
            }
        }
    }
}

The main dependency works fine but the test dependency gives the gradle error:

Could not determine the dependencies of task ':yass2-tail:jvmTest'.
> Could not resolve all task dependencies for configuration ':yass2-tail:jvmTestRuntimeClasspath'.
   > Could not resolve project :yass2-core.
     Required by:
         project :yass2-tail
      > Selected configuration 'commonTestImplementation' on 'project :yass2-core'
        but it can't be used as a project dependency because it isn't intended for consumption by other components.

So what is the correct way to define the test dependency?

1 Like

I am having the same issue. Did you ever figure out how to fix this?

Unfortunately not :frowning:

You are configuring a project not from it’s folder but from an external build file. You cannot do that as explicitly stated by the error:

Selected configuration 'commonTestImplementation' on 'project :yass2-core' 
but it can't be used as a project dependency because it isn't intended for 
consumption by other components.

Configure each project in its build.gradle.kts and then reference them only for dependency input, and not much else!