In this Scala tutorial session, I will cover SBT project layout and create our first Hello
Scala program. Project layout
is the default location of different types of files in your project. This video will explain
Most of the build tools assume a default project directory structure. SBT borrows its project Layout from maven. So, it looks like this.
Let me explain it quickly.I keep all my project folders in a top-level workspace directory. So,
sbt_workspace is the workspace directory. Inside, I have a project folder.
HelloScala is my first project. Typically, every project should follow the structure
shown in the image.
The first thing is the project build definition file. I will show you this file later, for now, let's focus on the directory structure. The second level directory src is for your source code. We break it further into main and test folders. The main folder is where you create application code, and test folder is for unit test code.
One useful feature of SBT is that it supports a mixed project. I mean, you can write code in Java as well as in Scala within the same project. That's why we have java as well as scala folder. You should keep all your project resources in the resources directory.
When you compile your project, SBT will create two more folders. The project and the target. SBT will generate your class files and jar files in the target folder. You can ignore the project folder for now. We will come back to it later.
The image shows the standard project layout, and it is recommended to follow this structure for large projects. But the SBT comes with lots of defaults, and the project directory layout is optional.
That makes it extremely convenient for small projects. You can create a new project directory, and straightaway start creating Scala code.
You don’t need to follow any directory structure and can also skip the build definition file. You can easily compile and execute your code using sbt run command. Simple isn't it.
We will explore SBT further in the next video.
Thanks for watching Learning Journal
Keep Learning and keep growing.