I am trying to do in kotlin-dsl what is described here in groovy:
https://stackoverflow.com/questions/5644011/multi-project-test-dependencies-with-gradle
dependencies {
...
testCompile project(':A').sourceSets.test.output
}
Is it possible in kotlin-dsl?
Many thanks
That same code in the kotlin DSL would be something like this:
dependencies {
...
testCompile(project(":A").java.sourceSets.test.output)
}
~That being said, I think if you use the java-library plugin you automatically get the test source sets added when you add a dependency on the project (don't quote me).~ (I was wrong, this was just because of an IntelliJ bug)
Another better way to do this is to create a configuration that publishes the test class outputs as an artifact from the project.
Then you could depend upon it by doing something like this project(":A", "test").
Thanks. That works
Having the same problem with the latest version. .java does not exist on the projectDependency object. any other workarounds? @JLLeitschuh suggest creating a configuration that publishes the test class outputs as an artifact from the project. are there any examples somewhere?
The solution that I go with primarily is to create a separate project. For example, if my sub-project is called "core" then I make a second sub-project called "coreTestUtils" where I put the test utilities that I want to share with other projects.
This is by far the cleanest solution I have figured out so far.
@JLLeitschuh Thanks! I found this jartest plugin which seems to work fine so far.
Any thoughts on this plugin?
I don't really have any thoughts on it. If it works, awesome. Both seem to achieve the same goal.
For another option, I translated the jartest plugin logic to a kts snippet:
configurations.register(
"testArchive"
) {
extendsFrom(configurations.testCompile.get())
}
tasks.register<Jar>(
name = "jarTest"
) {
from(project.sourceSets.test.get().output)
description = "create a jar from the test source set"
archiveClassifier.set("test")
}
artifacts {
add("testArchive", tasks.getByName("jarTest"))
}
with the other module depending on it like:
dependencies { testImplementation(project(":mysubproject", "testArchive")) }
Seems to work okay