title: In an SBT multi project build, how to reference projects from other folders?
body: <p>I am trying to tidy up my huge SBT multi-project build. Currently, I have everything in one big SBT file, but I am trying to fan this out into several directories.</p>
  
  <p>In a nutshell, this is my folder structure:</p>
  
  <pre><code>root
  +-foo
  | +-foofoo
  | | +-build.sbt
  | +-build.sbt
  | |
  | +-foobar
  | | +-build.sbt
  | +-build.sbt
  | |
  | bar
  | +-barfoo
  | | +-build.sbt
  | +-build.sbt
  | |
  +-build.sbt
  </code></pre>
  
  <p>In <code>root/build.sbt</code> I have:</p>
  
  <pre><code>lazy val root = project.
    in(file(".")).
    settings(publishArtifact := false).
    aggregate(foo,
              bar)
  
  lazy val foo = project in file("foo")
  lazy val bar = project in file("bar")
  </code></pre>
  
  <p>In <code>foo/build.sbt</code> I have:</p>
  
  <pre><code>lazy val foo = project.
    in(file(".")).
    settings(publishArtifact := false).
    aggregate(foofoo,
              foobar)
  
  lazy val foofoo = project in file("foofoo")
  lazy val foobar = project in file("foobar")
  </code></pre>
  
  <p>In <code>bar/build.sbt</code> I have:</p>
  
  <pre><code>lazy val bar = project.
    in(file(".")).
    settings(publishArtifact := false).
    aggregate(barfoo)
  
  lazy val barfoo = project in file("barfoo")
  </code></pre>
  
  <p>Now, I want <code>barfoo</code> to depend on <code>foofoo</code>, so, naïvely, I defined in <code>barfoo/build.sbt</code>:</p>
  
  <pre><code>lazy val barfoo = project.in(file(".")).dependsOn(foofoo)
  </code></pre>
  
  <p>But when running <code>sbt compile</code> it complains it can't find <code>foofoo</code>.</p>
  
  <p>So, how to correctly reference these intra-project dependencies?</p>
  
  <p>Currently the only way I can think of is to run <code>sbt foo/publishLocal</code> first and then add this as <code>libraryDependencies</code>. Is this the only way or is there another one?</p>
  
  <h1>Followup 1</h1>
  
  <p>After some digging, I read that <code>ProjectRef</code> should do the trick, but this gives me another error:</p>
  
  <p>I have some common dependencies in a <code>Dependencies.scala</code> object in my <code>project</code> subfolder. This is found by all subprojects. However when I define:</p>
  
  <pre><code>lazy val foofoo = ProjectRef(file("foo/foofoo"), "foofoo")
  lazy val barfoo = project.in(file(".")).dependsOn(foofoo)
  </code></pre>
  
  <p>I get this:</p>
  
  <pre><code>C:\Somewhere\bar\barfoo\build.sbt:1: error: not found: object Dependencies
  import Dependencies._
         ^
  </code></pre>
  
  <h1>Followup 2</h1>
  
  <p>I got it to work but I don't know if this is the right approach, so I leave it here but don't post it as an answer:</p>
  
  <pre><code>lazy val foofoo = project in file("../../foo/foofoo")
  lazy val barfoo = project.in(file(".")).dependsOn(foofoo)
  </code></pre>