I have multimodule project. From one of the modules I need to refer the test classes from other module. I tried to configure like this:
// core project
val testJar by tasks.registering(Jar::class) {
archiveClassifier.set("tests")
from(project.the<SourceSetContainer>()["test"].output)
}
val testArtifact by configurations.creating
artifacts.add(testArtifact.name, testJar)
And I'm trying to refer to that configuration from other project:
dependencies {
// other dependencies ommited
api(project(":core"))
testImplementation(project(path = ":core", configuration = "testArtifact"))
}
But this configuration doesn't work. The compilation of other project is failing as it doesn't see the required tests classes from core
project. The dependency insight:
./gradlew :service:dependencyInsight --dependency core --configuration testCompileClasspath
It gives following:
project :core
variant "apiElements" [
org.gradle.usage = java-api
]
variant "testArtifact" [
Requested attributes not found in the selected variant:
org.gradle.usage = java-api
]
I'm struggling to understand how to make configuration to work so that I can compile the service
project's test classes. Running on Gradle 5.2.1 with Kotlin DSL.