rabejens
rabejens

Reputation: 8122

Is it possible to create a hierarchical multi-project build with sbt?

I know this had been asked before but all these questions were either deleted or don't have satisfactory answers, so I ask it again:

In an SBT build, is it possible to arrange and define the subprojects in a hierarchical way? e.g.:

root
  foo
    foofoo
    foobar
  bar
    barfoo
    barbar

where each project has its own build.sbt but inherits settings from its top-level (aggregator) project (so foofoo and foobar inherit settings from foo and foo inherits settings from root)?

Maven has this possibility, but cross-building is quite painful with this one so I want to use SBT.

If it can be done, how is it done?

Upvotes: 5

Views: 793

Answers (2)

linehrr
linehrr

Reputation: 1748

refer to this: https://www.scala-sbt.org/0.13/docs/Multi-Project.html#Default+root+project

you can define multiple sbt files under sub-dirs and use root sbt to include them. they will be auto-merged into one big sbt to be run.

Any .sbt files in foo, say foo/build.sbt, will be merged with the build definition for the entire build, but scoped to the hello-foo project.

Upvotes: 0

oblivion
oblivion

Reputation: 6548

You can achieve this by configuring build.sbt of your root project. The build.sbt would look something like below in your case:

lazy val root = (project in file(".")).enablePlugins(PlayScala) //assuming its a play scala project

lazy val foo = project.in(file("<path-to-foo-project>")).dependsOn(root)

lazy val bar = project.in(file("<path-to-bar-project>")).dependsOn(root)

lazy val foofoo = project.in(file("<path-to-foofoo-project>")).dependsOn(foo)

lazy val foobar = project.in(file("<path-to-foobar-project>")).dependsOn(foo)

lazy val barfoo = project.in(file("<path-to-barfoo-project>")).dependsOn(bar)

lazy val barbar = project.in(file("<path-to-barbar-project>")).dependsOn(bar)

Upvotes: 3

Related Questions