Thursday, November 18, 2010

Day 2: Starting SBT

I want to program Scala for real. Like, big projects. And I don't want to feel like being cast back into the dark ages, of relying on IDEs to take care of automated builds. As far as I am concerned, all of the goodness that I can rely on in the Java world should be present in the Scala world as well. It may be sub-optimal for a while, but I need to have something to hold on to.

Having a tool for automating your builds is a must. I don't feel like going to Make or Rake or even Gradle. It just doesn't feel right. I'd be interested to work with Maven, but then again, that would be a little bit too comfortable, and the whole idea is that I would step out of this comfort zone, to get used to something else. Other than that, the word is out that Scala builds can be quite slow, compared to Java builds, and it turns out using the Maven plugins is aggravating it. (Devoxx Scala BOF.) So, let's try something else. Let's try simple-build-tool (SBT).

Giving it a go

So, down below you see me giving it a go. For some reason, Jing didn't record the audio, and I didn't really feel like doing it all over again, so I will explain what's going on below in a few bullets:

  • First, I am downloading SBT. SBT isn't packaged as a tar file with scripts, so you will have to create an installation directory yourself. In my case, I create the installation directory, download the jar, and then create a softlink in order to be able to address the directory a little easier.
  • Next, I am running SBT in an example directory. This will create the project files, and in fact copy loads of jar files into the directory. That feels a little funny at first, when you're used to Maven, but there will probably be a reason for it.
  • Notice that in this particular case, when SBT asks me about creating project files, I don't answer with 'y' (yes), but instead type 's'. Normally, SBT will assume files to exist in src/main/scala and src/test/scala. If I enter 's' at project construction time, it will add the project root to the list of folders containing Scala files as well - which is convenient if all you want to do is play around with SBT.
  • I already added a HelloWorld Java class, so once SBT is getting started, just typing compile will compile the class. Typing run, will run the class. Notice that - once I run 'run' - the compilation phase will detect that the classes have already been compiled and the sources haven't changed. Which is one reason why SBT is a little bit more convenient than the Scala Maven plugins.

Unable to display content. Adobe Flash is required.

No comments:

Post a Comment