Build Tools for Scala¶
In this section, we provide a brief overview of build tools for Scala. In general, build tools support the build process in several ways:
structured representation of the project dependency graph
management of the build lifecycle (compile, test, run)
management of external dependencies
Why Use a Build Tool?¶
When using the Java or Scala command-line tools, the developer is responsible for setting the dreaded classpath. This can quickly become unwieldy when dependencies even as simple as JUnit are involved, so this is not something you would usually want to do manually.
Brief History of Build Tools¶
- Unix make, Apache ant
These tools manage the build lifecycle but not external dependencies.
- Apache maven
This tool also manages external dependencies but requires a lot of XML-based configuraration.
1 <dependency>
2 <groupId>org.restlet</groupId>
3 <artifactId>org.restlet.ext.spring</artifactId>
4 <version>${restlet.version}</version>
5 </dependency>
- Apache ivy, Gradle, Scala’s Simple Build Tool (sbt), etc.
These tools emphasize convention over configuration in support of agile development processes. sbt is compatible with ivy and designed primarily for Scala development. For example, ivy uses a structured but lighter-weight format:
1 <dependency org="junit" name="junit" rev="4.11"/>
sbt¶
In the simplest case, sbt does not require any configuration and will use reasonable defaults. The project layout is similar to that used by Maven:
Production code goes in
src/main/scala
.Test code goes in
src/test/scala
.
sbt supports two configuration styles, one based on a simple Scala-based domain-specific language, and one based on the full Scala language for configuring all aspects of a project.
build.sbt format¶
A minimal sbt build.sbt
file would look like this. The empty lines
are required, and the file must be placed in the project root folder.
1 name := "integration-scala"
2
3 version := "0.0.2"
Additional dependencies can be specified either one at a time
1 libraryDependencies += "com.novocode" % "junit-interface" % "0.10" % "test"
or as a group
1 libraryDependencies ++= Seq(
2 "org.scala-lang" % "scala-actors" % "2.10.1",
3 "com.novocode" % "junit-interface" % "0.10" % "test"
4 )
Build.scala format¶
Examples of more complex Scala-based project configurations can be found in these examples:
Plugin Ecosystem¶
sbt includes a growing plugin ecosystem. Key examples include
- sbteclipse
automatically generates an Eclipse project configuration from an sbt one.
- sbt-start-script
generates a start script for running a Scala application outside of sbt.
The IntelliJ IDEA Scala plugin also integrates directly with sbt.