With this post, I will try to begin a series of translations of official documentation about the tool, which with the current growth of the Scala language is becoming more and more popular, but about which, nevertheless, very little information in Russian.
It will be a question of sbt - the project building system for the Scala language (although it is important to mention that Java projects (and any other in general) can also be built for them).
The article is the beginning of the translation of documentation from the site of the project
scala-sbt.org and since this is my first translation experience, I will be glad to any comments and corrections.
Also, due to the fact that while the translation is in the form of an article, I will skip moments that would not look quite correct, in the context of a separate part of the guide.
Foreword
Sbt, using a small number of concepts, offers flexible solutions to build projects.
This guide will tell you about some of the points that are needed to create and support build solutions using sbt.
This guide is highly recommended. But, if you don’t have time to read everything, you can read the most important information in the sections
“Build Parameters .sbt” ,
“ Build Areas” ,
“Additional Build Parameters” . But, we do not promise that this good idea will help you skip all the pages of this guide.
It is best to read this document sequentially, based on the material covered earlier.
Thanks for using sbt! We wish you to get maximum pleasure from this!
1. Installing sbt
To create a sbt project you need to do the following steps:
- Install sbt and create startup script
- Create a simple project “Hello world”
- Create project directory with source files inside
- Describe build options
- Read how to run sbt
- Continue reading the sbt build options guide.
Ultimately, the installation comes down to running the JAR file and the shell script. But, we describe several paths for different platforms that can make installation less tedious.
If you have problems running sbt, see the
“Installation Notes” section.
1.a. Mac installation
Using Macports
$ port install sbt
Homebrew
$ brew install sbt
1.b. Installation under Windows
Just download the
msi installer and run it.
')
1.c. Installation for Linux
Officially supported distributions:
RPM package
Deb package
In the future, I will talk about how you can download and configure sbt manually. For now, the most interesting.
2. Hello, World
Create a project directory with source code
One of the correct variants of the sbt project may be a directory containing one file with source code. Try creating a hello directory with the hw.scala file, with the following contents:
object Hi { def main(args: Array[String]) = println("Hi!") }
Now, in the directory itself, run sbt and type the run command in the interactive console. On Linux or OS X, it looks like this:
$ mkdir hello $ cd hello $ echo 'object Hi { def main(args: Array[String]) = println("Hi!") }' > hw.scala $ sbt ... > run ... Hi!
When creating a project, sbt works in accordance with the following rules:
- The source is in the root directory
- The sources are in the directory src / main / scala or src / main / java
- Tests are in src / test / scala or src / test / java
- Resource files in src / main / resources or src / test / resources
- Jar files in the lib directory
By default, sbt will compile a project with the version of scala with which sbt was launched by itself.
In addition to launching the console, the project can be immediately launched for execution with the
sbt run command.
Build options
Most projects still need more complex customization of the build process. In sbt, the main build parameters are stored in the
build.sbt file in the project root directory.
For example, if for our project hello to create a settings file, then it would look like this:
name := "hello" version := "1.0" scalaVersion := "2.10.3"
Note the blank lines. This is not just the case; they are actually required to separate the lines in the configuration file and without them sbt will generate an error. We will return to this file in more detail in subsequent sections.
Install sbt version
You can forcefully download and install the required version of sbt if you register the following line in the file hello / project / build.properties:
sbt.version=0.13.5
Now, at startup, the sbt version 0.13.5 will be used. If it is not, then the creak will download and install it in the system.
The version of sbt should be stored in the project / build.properties file to avoid possible collosies.
As a conclusion
For the experiment, I decided to limit myself only to these very first sections, and if the reaction is more or less positive, I hope to continue translating the rest.
PS I would be very grateful for the indicated inaccuracies and remarks of the translation. Thank!