Skip to content
This repository has been archived by the owner on Aug 19, 2020. It is now read-only.

Multi Project Test Dependencies #577

Closed
NikolayMetchev opened this issue Oct 26, 2017 · 7 comments
Closed

Multi Project Test Dependencies #577

NikolayMetchev opened this issue Oct 26, 2017 · 7 comments

Comments

@NikolayMetchev
Copy link

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

@JLLeitschuh
Copy link
Contributor

JLLeitschuh commented Oct 26, 2017

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").

@NikolayMetchev
Copy link
Author

Thanks. That works

@netanelrabinowitz
Copy link

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?

@JLLeitschuh
Copy link
Contributor

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.

@netanelrabinowitz
Copy link

@JLLeitschuh Thanks! I found this jartest plugin which seems to work fine so far.
Any thoughts on this plugin?

@JLLeitschuh
Copy link
Contributor

I don't really have any thoughts on it. If it works, awesome. Both seem to achieve the same goal.

@xbao
Copy link

xbao commented Aug 26, 2019

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

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Projects
None yet
Development

No branches or pull requests

5 participants