Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to specify that to build project A another project B has to be built first?

Tags:

scala

sbt

Suppose one guy in my company has an sbt project called commons that's pretty general-purpose. This project is defined in the traditional sbt way: in the main folder with the build definition in project/Build.scala file.

Now some other guy is developing a project called databinding that depends on commons. We want to define this project in the same way, with project/Build.scala.

We have the following directory layout:

dev/
  commons/
    src/
      *.scala files here...
    project/
      Build.scala
  databinding/
    src/
      *.scala files here...
    project/
      Build.scala

How can I specify that databinding requires commons to be built first and use the output class files?

I read Multi-project builds, and came up with the following for the build definition of databinding:

object MyBuild extends Build {

  lazy val root = Project(id = "databinding", base = file(".")) settings (
    // ... omitted
  ) dependsOn (commons)

  lazy val common = Project(id = "commons",
    base = file("../commons")
  )

}

Except it doesn't work: sbt doesn't like the .. and throws an AssertionError. Apparently, commons should be a folder inside databinding. But these two projects are kept in separate git repositories, which we cannot nest.

How can this dependency be specified properly?

like image 942
Jean-Philippe Pellet Avatar asked Nov 30 '11 17:11

Jean-Philippe Pellet


1 Answers

You need to define the multi-project in a root project (or whatever name but this one fits well) that will be define in dev/project/Build.scala.

object RootBuild extends Build {
  lazy val root = Project(id = "root", base = file("."))
    .settings(...)
    .aggregate(commons, databinding)

  lazy val commons = Project(id = "commons", base = file("commons"))
    .settings(...)

  lazy val databinding = Project(id = "databinding", base = file("databinding"))
    .settings(...)
    .dependsOn(commons)
}

one more thing, SBT doesn't support *.scala configuration files in sub-projects. This means that you will have to migrate the configuration you made on commons/project/Build.scala and databinding/project/Build.scala into respectively commons/build.sbt and databinding/build.sbt.

If some of your configuration are not suitable for a .sbt definition file, you will have to add them in the root project/Build.scala. Obviously, settings defined in root Build.scala are available in *.sbt files.

like image 130
David Avatar answered Feb 07 '23 12:02

David