Hello,
i am a litte bit lost. I use gradle 5.5.1 with the kotlin-dsl and develop kotlin apps for the jvm.
I want to setup a source code organisation like the following, for my projects:
src/main/ <- implementation
src/test/ <- tests
src/testSupport/ <- test infrastructure
I want that every project has its testsupport, which contains Junit5 Extensions, Mock-Classes, Custom Asserts etc pp. testSupport
can see the classes from main
and test can see classes from testSupport
and main
I have the following attempt:
val testSupportSourceSet = sourceSets.create("testSupport") {
compileClasspath = project.files("src/testSupport/")
runtimeClasspath = project.files("src/testSupport/")
}
val testSupportImplementation by configurations.getting {
extendsFrom(configurations.implementation.get())
extendsFrom(configurations.testImplementation.get())
}
dependencies {
applyDependencies()
testImplementation(testSupportSourceSet.output)
testSupportImplementation(sourceSets["main"].output)
}
val testSupportJar by tasks.registering(Jar::class) {
from(testSupportSourceSet.allJava)
}
artifacts {
archives(testSupportJar)
}
This works fine in IntellJ. However, when I execute the tests via ./gradlew test
in the testSupport-Source-Set literally no dependency is resolved. Every import failed:
Unresolved reference: kotlin
Unresolved reference: ImmutableSet
and so one.
I also usually have a multi-project setup and I declared the testSupport dependency like so:
testImplementation(project(":subproject", configuration = "testSupportImplementation"))
Again: This works fine in IntelliJ, but in gradle I got:
Selected configuration 'testSupportImplementation' on 'project :myProject' but it can't be used as a project dependency because it isn't intended for consumption by other components
Can somebody give me some hints in the right direction?
Thank you