I have a project that has a source set containing code that is used in both the unit test suite and integration test suite of the project. The code in this source set makes use of functionality defined by the test dependencies shared by the aforementioned test suites.
Here is a snippet of the build.gradle.kts
file of the project which attempts to declare dependencies for the aforementioned source set using those already declared for the unit test suite:
dependencies {
testImplementation("io.kotest:kotest-runner-junit5:4.4.2")
testImplementation("io.kotest:kotest-assertions-core:4.4.2")
testImplementation("io.mockk:mockk:1.10.6")
}
val commonTestResourceSourceSet = sourceSets.create("commonTestResource")
val commonTestResourceImplementationConfiguration = configurations.getByName(commonTestResourceSourceSet.implementationConfigurationName)
commonTestResourceImplementationConfiguration
.extendsFrom(configurations.getByName("testImplementation").copyRecursive())
Attempting to run the unit test suite of the project (using the command ./gradlew test
) when the project is configured is such a way results in failure, with error messages like those below which indicate that the dependencies of the configuration that was extended in the snippet were not resolved:
e: /path/to/project/src/commonTestResource/.../foo.kt (3, 8) : Unresolved reference: io
e: /path/to/project/src/commonTestResource/.../foo.kt (11, 44) : Unresolved reference: shouldBe
Declaring the dependencies of interest directly in commonTestResourceImplementationConfiguration
, however, enables the commonTestResource
source set to be compiled successfully during attempts to run the the unit test suite of the project.
If I understand the documentation, the direct and indirect declaration of dependencies should be functionally equivalent in this scenario:
A configuration can extend other configurations to form an inheritance hierarchy. Child configurations inherit the whole set of dependencies declared for any of its superconfigurations.
Why then, does that not appear to be the case?