# Understanding Project dependencies

**URL:** <https://discuss.gradle.org/t/understanding-project-dependencies/17895>\
**Category:** Help/Discuss\
**Created:** [June 3, 2016, 6:20am UTC](https://discuss.gradle.org/t/understanding-project-dependencies/17895 "2016-06-03T06:20:42Z")\
**Posts on this page:** 4\
**Page:** 1

<div class="post-metadata">

**Author:** ![anna](https://avatars.discourse-cdn.com/v4/letter/a/779978/32.png) [@anna](https://discuss.gradle.org/u/anna)\
**Post date:** [June 3, 2016, 6:20am UTC](https://discuss.gradle.org/t/understanding-project-dependencies/17895/1 "2016-06-03T06:20:42Z")

</div>

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:

dependencies{  
testCompile project(":ProjectA")  
testCompile project(":projectA").sourceSets.main.output  
testCompile project(path: “projectA”, configuration: “compile”)  
}

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.

Any help will be appreciated.

---

<div class="post-metadata">

**Author:** ![Lance\_Java](https://sea1.discourse-cdn.com/gradle/user_avatar/discuss.gradle.org/lance_java/32/787_2.png) [@Lance\_Java](https://discuss.gradle.org/u/Lance_Java)\
**Post date:** [June 3, 2016, 8:38am UTC](https://discuss.gradle.org/t/understanding-project-dependencies/17895/2 "2016-06-03T08:38:41Z")

</div>

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](http://stackoverflow.com/questions/19936915/gradle-what-is-the-default-configuration-and-how-do-i-change-it)

Take a look at the “Project dependencies” section in the DependecyHandler documentation [here](https://docs.gradle.org/current/javadoc/org/gradle/api/artifacts/dsl/DependencyHandler.html) for more info on the `project(...)` method.

---

<div class="post-metadata">

**Author:** ![anna](https://avatars.discourse-cdn.com/v4/letter/a/779978/32.png) [@anna](https://discuss.gradle.org/u/anna)\
**Post date:** [June 3, 2016, 6:51pm UTC](https://discuss.gradle.org/t/understanding-project-dependencies/17895/3 "2016-06-03T18:51:08Z")

</div>

Thanks for the response Lance\_Java!

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?

---

<div class="post-metadata">

**Author:** ![Lance\_Java](https://sea1.discourse-cdn.com/gradle/user_avatar/discuss.gradle.org/lance_java/32/787_2.png) [@Lance\_Java](https://discuss.gradle.org/u/Lance_Java)\
**Post date:** [June 7, 2016, 2:42pm UTC](https://discuss.gradle.org/t/understanding-project-dependencies/17895/4 "2016-06-07T14:42:17Z")

</div>

`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

```gradle
configurations {
   nonTrans { transitive = false }
   testCompile.extendsFrom nonTrans
}
dependencies {
   nonTrans project(":projectA")
}

```

For exploration, it’s pretty easy to print out the result. Eg:

```gradle
configurations.testCompile.files.each {
   println it
}

```
