In this post I am introducing a source kit ( ScalaGoodies), for installing my current favorite selection of Scala development tools, incidentally also available for free. Here is a bird’s-eye view of what you can get:
Using my kit you should be able to add easily to your Scala project:
- the Atom editor configured for Scala including powerful completions (courtesy of Ensime)
- the ability to evaluate Scala code directly from Atom (thanks to Hydrogen)
- a better
sbtlauncher and also a terminal in Atom for launching it
- Jupyter, an advanced web based REPL (a.k.a. Noteebook), including the excellent jupyter-scala kernel for evaluating you Scala code.
If you are interested in this tools, read on for a description of how to install and use them quickly and easily.
As Scala developer, I started to code using initially the free Scala-IDE. Later, I switched to the paid IntelliJ Idea IDE with the Scala plugin.
In the meanwhile, the ecosystem of Scala development tools improved, to the point it is now possible to have a development experience similar to those IDES, for free. The avalilable features rival, and sometimes surpass, those offered by their commercial counterpart. Indeed, this collection of tools is currently my favorite development environment.
An advantage of using multiple development tools than a monolitic IDE is you can enable the tools you need and leave out those who don’t, since each one is optimized only for one purpose. The disadvantage is putting all of them together is sometimes complicated and time expensive.
For this reason, I created a source kit to make things easier. Of course initially I wrote it just for myself, but since I believe it is useful to a wider audience, I am sharing it with everyone on GitHub: ScalaGoodies
Being a source kit, it is based on
git. So, an absolute prerequisite to use this kit is you need git installed. It can be used even if your project is under version control with other VCS, but you need to install Git first.
If you are using
git, your local git installation should be already fine. If you are not using
git as you version control, you need to initialize executing
git init from the top level directory of your project. Once initialized, you can proceed as described below.
The kit has been tested on OSX 10.10 and Windows 10, but it should work also on any “normal” Linux distro.
Before starting, as I said, you need
git including a
bash shell. All the scripts are in
bash, even for Windows. Since Windows is moving to
bash too, and Git for Windows already provides a pretty good
bash, there is little point in using another tool. You need also a Java Development Kit, Atom and Python, as described below.
You should start opening the bash shell. Then, change to the directory of your source project. Now, to use the whole kit, you need to execute the following commands. You can actually skip some of them, as described later here.
git remote add ScalaGoodies https://github.com/sciabarra/ScalaGoodies
You do not need to install all the features though.
- You can skip the merge
esbtif you do not want an advanced SBT
- you can skip the merge
completionif you do not want to use the Atom editor with completion
- you can skip the merge
worksheetif you do not want an advanced REPL (or if you are using Windws…)
Note the installation of the worksheet you ask for the root password, to install the python libraries for Jupyter.
Also note the prerequisites:
- to merge
esbtyou need to pre-install the Java Development Kit
- to merge
completionyou need to pre-install the Atom editor
- to merge
worksheetyou need to pre-install Python 2.7 and a compiler
It is actually not easy to install the worksheet on windows, as it requires a compiler and sudo. I recommend to skip the installation of the worksheet on Windows, but YMMV. I was unable to complete the installation of the worksheet on window for this reason, while on Linux and OSX is pretty easy.
Now, let’s see what we have installed.
Ensime is a code analysis tool, intially written to provide advanced completion for Scala for the Emacs Editor. However it is a generic server that can be used with other editors, including Atom.
To use Atom with Ensime, if you used my installer, all you need to do is to run
bin/atom.sh from your project folder. When Atom shows up, the first time it will also download some dependencies:
The important thing to remember is: to get completions, you need to manually start Ensime. To do so, type the sequence
control+shift+p on Windows or
command+shift+P on Mac to invoke the command palette, then search for
Ensime: Start and execute it.
The reason of this complicated startup lies in the idea that Atom is based on commands. Some commands can be activated with keystrokes but not all. The less frequent ones must be invoked from the command palette. Starting Ensime is not a frequent commands, you do it once per session. So there is not a direct keystroke.
Note also the first time it runs, Ensime will download some depenendencies. You are ready when you see the Ensime Connected message.
Now you are ready to use Ensime. Open a Scala file and you will enjoy a number of features available, demostrated here:
The most important features is, of course, code completion. Just start to type an expression, and the editor will give you a list of the legal completions available. Needless to say, it is a huge time saving, the feature that usually mandates the adoption of a full IDE specific for your language, instead of a generic text editor.
Another key feature for Scala is type information. Just moving the cursor over a variables will tell you the type of the variable. For Scala, this feature is invaluable, given the type inference.
In the picture you can also notice the error messages that appear as you type your code, doing a sort of “compilation” on-the-fly. Other features are available, you can check here for details.
A very nice feature of some IDEs is the notebook. In short, it the ability to type code and evaluate it on the fly. It is very similar to the classical console available for Scala and other languages, except the notebook will keep a track of what you have typed before, and you can re-execute the code without having to type it again.
Let’s see Jupyter first. You can start it with the script
bin/jupyter.sh. It will open a web browser, showing a file browser. You can create a new notebook, selecting
Scala 2.10 or
Scala 2.11 and you will get a web page where you can type your scala code and evaluate it.
Jupyter is very useful and I use it for all my exploratory coding.
But what I think is is a really winner feature is the ability to use Atom and evaluate the code directly from the source you are editing.
All you have to do is to highlight a snippet of code and press
alt+shift+enter, and a windows will appear after the cursor showing the result.
This feature is actually provided by the same engine that powers Jupyter, and it is installed together Jupyter. The Atom plugin doing the magic is Hydrogen and it is powered by this Scala-Jupyter kernel, which in turn it uses Ammonium (a fork of the Ammonite REPL).
In addition to the Atom based plugins, I included some command line tools to enhance SBT.
esbt branch provides:
- Paul Phillips
- scripts to run sbt keeping artifacts under
- a terminal plugin for Atom
You can just use
bin/sbt.sh with a number of features on the command line. However, my preferred configuration (although not mandatory) is using the options provided by
As you may know, sbt usually keeps many files outside of your project directory. I do not like this for a number of reasons, and I like to have everything under my project folder.
I provided the script
esbt.sh to do exactly this, placing everything under the
project folder. If you I use
esbt.sh, it will use a locally installed
bin, it will place the boot directory of sbt under
project/boot, and the sbt repository under
project/ivy2. Note also the atom configuration is placed under
Last but not least, I included in the Atom installation also the terminal plus plugin so you can run those commands from within Atom.
In short, ScalaGoodies should make easy to setup a modern and powerful Scala development enviroment. Since I use it, I almost gave up using IntelliJ Idea. I feel I have all I need for productive work with a more lightweight, flexible and customisable enviroment.