Scala, SBT, Maven and a little Idea

After playing around with a lot of IDEs I settled with IntelliJ Idea for Scala development.

This was during the time of Scala 2.8 development where every week brought a new version.

I just wanted to play around with Scala and didn’t mind to stick with 2.7.

Eclipse was way to fragile at that time, netbeans just didn’t work at all and Idea at least had some working code completion and syntax highlighting.

The cool thing about Idea is its capability to let an outside tool do the building without breaking completely (curse you, Eclipse workspace). So the next thing was to look for a cool build system. I have to use Maven a lot in other projects so I was looking for something that would allow me to reuse the Maven repository infrastructure.

SBT was exactly what I have been looking for.

SBT is very convenient replacement for Maven as it supports its Repositories and uses Scala as its scripting language.

  • Download SBT
  • Run it in an empty directory
  • Answer the questions
  • Get to see the glorious SBT-shell

This is the SBT-shell which allows interacting with SBT. From here you just type “run” or “test” or “update” or some other commands to interact with SBT.

Now let’s take a look at the directory layout:

  • lib
  • project
    • boot
    • build.properties
  • src
  • target

Src and target save the same purpose as in a Maven build, the layout beneath is the same.

The next step is to create a Project class in project/boot:

import sbt._
class MyProject(info: ProjectInfo) extends DefaultProject(info) {
      val derby = "org.apache.derby" % "derby" % "10.4.1.3"
}

The above sourcecode defines a dependency to apache derby. So this project file is used to configure dependencies and a lot of other things.
In my case I wanted to be able to also build the project from Maven to allow non-Scala-developers to use my stuff.
The docs told me about SBTs pom-support so went for it and build my pom. I put it into the root directory and Maven was happy.
SBT wasn’t. It complained about not being able to locate artifacts.
Turnes out that setting a property in the project file does the trick:

import sbt._
class MyProject(info: ProjectInfo) extends DefaultProject(info) {
      val mavenLocal = "Local Maven Repository" at "file://"+Path.userHome+"/.m2/repository"
}

Now that SBT is actually using the local Maven repository everything is working fine.
Now start SBT in your project-dir, start Idea and import the pom.
Happy Coding :D

Follow

Get every new post delivered to your Inbox.