# Reference external project as dependancy?

**URL:** <https://discuss.gradle.org/t/reference-external-project-as-dependancy/6134>\
**Category:** Old Forum Archive\
**Created:** [May 18, 2013, 6:37pm UTC](https://discuss.gradle.org/t/reference-external-project-as-dependancy/6134 "2013-05-18T18:37:00Z")\
**Posts on this page:** 5\
**Page:** 1

<div class="post-metadata">

**Author:** ![Abrar\_Syed](https://sea1.discourse-cdn.com/gradle/user_avatar/discuss.gradle.org/abrar_syed/32/599_2.png) [@Abrar\_Syed](https://discuss.gradle.org/u/Abrar_Syed)\
**Post date:** [May 18, 2013, 6:37pm UTC](https://discuss.gradle.org/t/reference-external-project-as-dependancy/6134/1 "2013-05-18T18:37:00Z")

</div>

Hi Everywhere I have looked in the userguide, all the project dependencies must be in the same project tree. A root project must exist, and then subprojects existing within the directory (or sub-sub projects I guess) of the root project.

Is there a way where I can define a project elsewhere in the filesystem, and then reference it as a project dependency from a project without being locked to the root \> subproject directory structure?

---

<div class="post-metadata">

**Author:** ![Peter\_Niederwieser](https://avatars.discourse-cdn.com/v4/letter/p/9f8e36/32.png) [@Peter\_Niederwieser](https://discuss.gradle.org/u/Peter_Niederwieser)\
**Post date:** [May 19, 2013, 4:44am UTC](https://discuss.gradle.org/t/reference-external-project-as-dependancy/6134/2 "2013-05-19T04:44:00Z")

</div>

A project can live anywhere on the file system. The _logical_ project structure is always a tree; the _physical_ project directory structure is arbitrary. See ‘Settings’ in the [Gradle Build Language Reference](http://gradle.org/docs/current/dsl/index.html) for how to configure project directories. I’m pretty sure it’s also explained in the [Gradle User Guide](http://gradle.org/docs/current/userguide/userguide_single.html) (see the chapter on multi-project builds).

---

<div class="post-metadata">

**Author:** ![Olaf\_Groeger](https://avatars.discourse-cdn.com/v4/letter/o/59ef9b/32.png) [@Olaf\_Groeger](https://discuss.gradle.org/u/Olaf_Groeger)\
**Post date:** [June 2, 2013, 9:25am UTC](https://discuss.gradle.org/t/reference-external-project-as-dependancy/6134/3 "2013-06-02T09:25:00Z")

</div>

If i might add a word here.

As far as i understand the DSL reference it is not possible to do this because the only possibility to add Projects is through the include or includeFlat methods, which evaluate the file path relative to the directory where the settings.gradle reside and its parent, respectively.

But if you leave the API behind, you could use the createProjectDescriptor method of the Settings implementation:

Settings.gradle:

```gradle
def projectADir = file('../projectA')
def projectBDir = file('../projectB')
  def rootProjectDescriptor = settings.rootProject
  settings.createProjectDescriptor(rootProjectDescriptor, 'projectA', projectADir)
settings.createProjectDescriptor(rootProjectDescriptor, 'projectBFake', projectBDir)

```

---

<div class="post-metadata">

**Author:** ![Peter\_Niederwieser](https://avatars.discourse-cdn.com/v4/letter/p/9f8e36/32.png) [@Peter\_Niederwieser](https://discuss.gradle.org/u/Peter_Niederwieser)\
**Post date:** [June 2, 2013, 9:37am UTC](https://discuss.gradle.org/t/reference-external-project-as-dependancy/6134/4 "2013-06-02T09:37:00Z")

</div>

‘include’/‘includeFlat’ _default_ to hierarchical/flat directory layouts, but this can be customized arbitrarily, using only public APIs. For example:

```gradle
include("foo")
  project(":foo") {
    projectDir = new File("$settingsDir/../../bar")
}

```

See [ProjectDescriptor](http://www.gradle.org/docs/current/javadoc/org/gradle/api/initialization/ProjectDescriptor.html) for further configuration options.

---

<div class="post-metadata">

**Author:** ![Olaf\_Groeger](https://avatars.discourse-cdn.com/v4/letter/o/59ef9b/32.png) [@Olaf\_Groeger](https://discuss.gradle.org/u/Olaf_Groeger)\
**Post date:** [June 2, 2013, 11:13am UTC](https://discuss.gradle.org/t/reference-external-project-as-dependancy/6134/5 "2013-06-02T11:13:00Z")

</div>

Got it. Thank you very much.
