Git Subproject Compile-time Dependencies in Sbt

26 Jun, 2015
Xebia Background Header Wave

When creating a sbt project recently, I tried to include a project with no releases. This means including it using libraryDependencies in the build.sbt does not work. An option is to clone the project and publish it locally, but this is tedious manual work that needs to be repeated every time the cloned project changes.
Most examples explain how to add a direct compile time dependency on a git repository to sbt, but they just show how to add a single project repository as a dependency using an RootProject. After some searching I found the solution to add projects from a multi-project repository. Instead of RootProject the ProjectRef should be used. This allows for a second argument to specify the subproject in the reposityr.
This is my current project/Build.scala file:

import sbt.{Build, Project, ProjectRef, uri}
object GotoBuild extends Build {
  lazy val root = Project("root", sbt.file(".")).dependsOn(staminaCore, staminaJson, ...)
  lazy val staminaCore = <b>ProjectRef</b>(uri("git://"), <b>"stamina-core"</b>)
  lazy val staminaJson = <b>ProjectRef</b>(uri("git://"), <b>"stamina-json"</b>)

These subprojects are now a compile time dependency and sbt will pull in and maintain the repository in ~/.sbt/0.13/staging/[sha]/stamina. So no manual checkout with local publish is needed. This is very handy when depending on an internal independent project/module and without needing to create a new release for every change. (One side note is that my IntelliJ currently does not recognize that the library is on the class/source path of the main project, so it complains it cannot find symbols and therefore cannot do proper syntax checking and auto completing.)

Joost Heijkoop
Passionate software developer working for Xebia and organiser at Amsterdam.scala, always looking to learn, share, help, teach and meet new people. Also a serial meetup and conference attendee.

Get in touch with us to learn more about the subject and related solutions

Explore related posts