Compiling sub projects in sbt

See Navigating projects interactively:

At the sbt interactive prompt, type projects to list your projects and project <projectname> to select a current project. When you run a task like compile, it runs on the current project. So you don't necessarily have to compile the root project, you could compile only a subproject.

You can use aggregate to compile them all.


Because the selected answer's linked documentation has changed, the answer isn't so clear anymore.

In the build.sbt of OP's main_project, to compile them together they will have to define an aggregate, as the new(er) documentation links to:

lazy val root = (project in file("."))
  .aggregate(util, core)

lazy val util = (project in file("util"))

lazy val core = (project in file("core"))

And then running an sbt compile in the root project's directory will compile them all.

However, if you wish to compile one at a time, you can navigate your cmd line/terminal to the root project ( main_project here) and then run the following command:

user:main_project$: sbt <project name> / compile

to use the poster's example:

user:main_project$: sbt sub_project1 / compile

(if you are in the SBT terminal, then you can omit sbt)

Tags:

Scala

Sbt