Saturday, 13 November 2010

Building Scala applications with SBT + Idea

Intellij IDEA is a great tool for Scala Developers. A couple of days ago I attended a great event of the London Scala User Group where, Richard Hallaway, Phill Wills and Maciej did a very good intro to this tool. This guide explains how to quickly leverage a couple of tools to setup a new Scala project in minutes.

First of all, start downloading right now the latest build of Idea X community edition for your platform, this will probably be ready by the time we finish with the setup. You'll also need the Scala and SBT plugin.

There are basically two ways to setup your idea projects with SBT. The first would be using Heiko Seerbergers guide to setup the project from Idea. I prefer to do it the way that Mikko Peltonen suggests... SBT-Idea.

First, you'll need the great SBT (Simple Build Tool), which is a build tool written in Scala and for Scala. Its power lies in that it relies on convention over configuration and giving you full control over your builds. No longer long XML configurations + Shell scripts. SBT can do everything from one single script. Furthermore, builds can pickup only the changes you made, and recompile and run only those tests. Check it out!

After you setup SBT  , create a new project:

sbt
Name:
Organization:
Scala: 2.8.1
sbt: 0.7.4

this will create most of your project.

then exit the console, go to project folder, and create a folder build and inside, a scala file such as this:





Go back to the sbt console, type update, and it will pull the dependencies.

Use the SBT processor as specified here:


> *sbtIdeaRepo at http://mpeltonen.github.com/maven/
 > *idea is com.github.mpeltonen sbt-idea-processor 0.1-SNAPSHOT 
 ...
 > update
 ...
 > idea
 ...

this will create your project. Now, import in IDEA. All your SBT structure will be recognized.

Now let's setup the FSC (Scala Fast Compiler Server). SBT is great for quick reloads, but i still prefer to have fast compilation within the IDE.

For that, just go to Edit Configurations in your run targets in the toolbar, and create a new Scala Compilation Server using the following details. I had issues in the past when ticking the box shared configurations but it probably has been fixed already.


That's all you need ! Super fast compilation within Idea. And remember if you run your commands in sbt with a tilde ~ they will automatically run every time you switch back to the sbt console and it detects a file change.

Finally, don't forget your .gitignore

.idea/
lib_managed/
project/boot/
project/build/target/
target/

Scala 2.8.1 released

Plenty of bug fixes (more than 100 in 3 months!). Great to see a very active community, kicking the tires and gathering to solve problems. Furthermore, It's fully binary compatible with 2.8, which means no need to match library versions as it happened with the RCs for 2.8. Also, the improvements to Scaladocs make it look very snappy

All in all, we can see the the Scala language growing at a fast pace. Many new books are coming, including Phillip Haller's Actors in Scala and three others by Manning "in Action" series. Browse the complete list of books if you are interested.