I started to learn Scala and almost in every tutorial I see a build.sbt
file which describes project settings. But now I have installed giter8
and created a project from template. And generated project from template missed build.sbt
file, but it have build.scala
(which seems used for same purposes, but it is more flexible).
So what is the difference between build.sbt
and build.scala
?
Which is more preferred and why?
If you call scala, you will get whatever scala version is installed on the path of your operating system. If you call sbt console, you get the scala version configured in the sbt build (build. sbt) with all libraries that are used in the build already on the classpath.
sbt is a popular tool for compiling, running, and testing Scala projects of any size. Using a build tool such as sbt (or Maven/Gradle) becomes essential once you create projects with dependencies or more than one code file.
sbt is an open-source build tool for Scala and Java projects, similar to Apache's Maven and Ant.
Project Information Over time some have re-defined sbt to stand for “Scala Build Tool”, but we believe that isn't accurate either given it can be used to build Java-only projects.
To give a brief example, this build.sbt
:
name := "hello" version := "1.0"
is a shorthand notation roughly equivalent to this project/Build.scala
:
import sbt._ import Keys._ object Build extends Build { lazy val root = Project(id = "root", base = file(".")).settings( name := "hello", version := "1.0" ) }
The .sbt
file can also include val
s, lazy val
s, and def
s (but not object
s and class
es).
See the SBT document called ".scala build definition", particularly the section "Relating build.sbt to Build.scala".
Consider a .scala
build definition if you're doing something complicated where you want the full expressiveness of Scala.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With