Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Factoring libraryDependencies in multi project Build.sbt

I'm trying to write a concise multi project Build.sbt, so I tried to put all library dependencies in root project and then make others depends on it. My Build.sbt looks like the following:

object KataBuild extends Build {

        lazy val fizzBuzz = Project(
            id = "fizzBuzz", 
            base = file("fizzBuzz"),
            settings = Project.defaultSettings ++ Seq(
                name := "fizzBuzz",
                version := "1.0",
                scalaVersion := "2.10.3"
            )
        )

        lazy val kata = Project(
            id = "scala-kata", 
            base = file("."),
            settings = Project.defaultSettings ++ Seq(
                name := "scala-kata",
                version := "1.0",
                scalaVersion := "2.10.3",
                libraryDependencies ++= Seq(
                    "org.scalatest" %% "scalatest" % "2.1.0" % "test"
                )
            )
        ) aggregate(fizzBuzz)

        fizzBuzz dependsOn(kata)

}

But running test from the main project (scala-kata) fails to build test for fizzBuzz. What am I missing?

like image 536
ilmirons Avatar asked Oct 29 '25 08:10

ilmirons


1 Answers

Your question is similar to this one. In short, fizzBuzz.dependsOn(kata) means that its compile configuration depends on the kata's compile configuration, but you want to link the test configurations.

The 'Per-configuration classpath dependencies' section of the sbt docs show you how you can make a test->test dependency instead.


However, if you are not going to use kata's test sources but are just looking for a way to include Scala-Test in fizzBuzz, just add it explicitly to fizzBuzz's library dependencies, too. You can define a helper value

lazy val scalaTest = "org.scalatest" %% "scalatest" % "2.1.0" % "test"

Then you can add it to be sub project's library dependencies (libraryDependencies += scalaTest).

like image 50
0__ Avatar answered Oct 31 '25 06:10

0__