I have two projects: project A – this one has the main code project B – this one has the test code (for some reason I have to keep test code in a separate project for a while)
Now in project B, I am adding a testCompile dependency configuration on project A. I want to understand the difference between these dependency configuration statements:
I am asking this question because I actually want to pull in all the compile time dependencies of project A into the testCompile dependency of project B and I can’t figure out how to do that. I assumed testCompile project(path: “projectA”, configuration: “compile”) will work, but it doesn’t.
I consider project(":projectA").sourceSets.main.output to be bad practice since I feel that the sourceSets of another project are private. Much better to define a configuration in the project and reference that instead.
project(":projectA") is equivelant to project(path: ":projectA", configuration: "default"). More info on the default configuration here
Take a look at the “Project dependencies” section in the DependecyHandler documentation here for more info on the project(...) method.
I have gone through a decent amount of documentation, but I just couldn’t understand one thing -
Will project(path: “projectA”, configuration: “compile”) automatically place project(":projectA").sourceSets.main.output on the compile classpath of test code in Project B? What else will it have? Will it also bring in the entire compileJava Classpath of Project A?
project(":projectA").sourceSets.main.output is a reference to the outputdirectory(s) so will not bring in the transitive dependencies. By default, testCompile project(":projectA") will also bring in the transitive dependencies. You could avoid this via