This document is meant to serve as introductory guide to using SBT. The SBT wiki contains a lot of information, but my opinion is that it could have been presented in a more digestible manner, especially for those that are new to Scala. I think one of the biggest problems with the documentation is that it starts with the simplified Build.sbt file, but to create a custom task, which will be necessary in many non-trival builds, requires using the more complex Build.scala format. I think think it might be better to present the concepts behind creating a Build.scala file, and then explain how the Build.sbt can be used for simplifying. That being said, if you need to build a simple jar, the SBT Getting Started Wiki, and the Build.sbt file will probably serve you well.
SBT uses a lot of custom operators like := and >>=. In my opinion, some of these operations would be much clearer if they just used function names instead of operators, but it appears that brevity has taken precedence. It is worthwhile reinforcing that in Scala, when you see something like this
a := b
this can be thought of as calling the function called ":=" on a, passing b as a parameter.
First things first. Your code should be in a "src/main/scala" directory and your resources should be in a "src/main/resources". The root of the project will be the directory that contains the "src" directory. If you have any jars that your project is dependent on, place them in a "lib" directory in the root directory (along side "src").
Running sbt with no configuration
If all of your project dependencies are in the lib directory, and you don't need to anything more complex, just run the following command from your root directory:
This should compile and run your project, assuming you have some sort of main function in your Scala code. If instead, you are just creating a library, the following should create a jar for you.
This all works by convention, and is quite nice when compared to other build systems. The rest of this tutorial will focus on customizing sbt to do more complex tasks.
The Build files
There are two types of ways to describe your build using SBT, one is a simplified format called Build.sbt, and the other is a Build.scala file. Build.sbt is a simplified version of Build.scala with some things already taken care of for you, but I am going to start with Build.scala because I think it will be easier to understand in the long run.
Thanks for reading, please leave any comments or corrections.