In my last post Create Scala Project with SBT. We had seen how it was easy with SBT to create a Scala project. In this post,we will learn multi Project Builds with SBT for Scala project.
It can be useful to keep multiple related projects in a single build. If they depend on one another and you tend to modify them together. Each sub-project in a build has its own SBT default directory. It is generate own build and works like any other project.
I have a main project parent and two sub-project child1 and child2. Lets quickly started with creating parent. In order to create project execute the following commands in the sbt session.
If we have multiple projects, we must declare each project and how they relate in Build.scala file. We can define settings for each project in build.sbt file. Here’s an example of a Build.scala file which defines a root project parent, where the parent project aggregates two sub-projects, child1 and child2. Which resides under parent/project/Build.scala.
Projects in the build can be completely independent of one another. For Multi Project Builds we call a method aggregate(child1, child2). This aggregates child1 and child2 underneath the parent project.
Aggregation will run the aggregated tasks in parallel and with no defined ordering.
Note : If we execute sbt clean compile command on console then it create two sub-directory child1 and child2 by default.It is not contain any project specific setting.
If we want project specific setting then executing following commands in the sbt session for sub-project.
If we compile our project from root then we can see with main project, sub-project also compile parallely, It is help full for large project which takes more time in compilation. So for resolving this problem we can develop our project under Multi Project Builds. By executing sbt compile command on console we can see
updating all projects at a time.
My whole project is in parent and i defined different version in parent\build.sbt ,parent\child1\build.sbt and parent\child2\build.sbt. Now we can check project version by executing show version command on sbt session.