Monday 17 September 2012

Building Scala apps with Maven and ScalaTest

Of the many Scala projects I know (particularly on Github), most rely on SBT for the build. However, no matter how convenient SBT is, some projects are more easily handled by Maven, even if it is because a lot of the infrastructure require to deploy large projects, is already managed by it.

I personally prefer SBT, in fact, you can use this project for quick Scala + SBT + IDEs setup.  But for the projects I have at work, Maven is used, so I need to have a decent project file.

But as soon as you start trying to build something, you realise that the build systems in Scala still are in beta stages. The amount of options, poor documentation, and conflicting views certainly doesn't help:
SBT (with all its versions), two Maven plugins, Intellij, the ever changing Scala IDE plugin and at least two main testing frameworks, ScalaTest and Specs. Oh, and don't forget Java / Scala mixed projects. It can certainly alienate a newcomer.

In particular, the two maven plugins: maven-scala-plugin, a scala-maven-plugin, have plenty of different posts on how to configure them, most if not all of them at various stages of decay and rot, even though some of this posts are fairly recent. Or what happens a lot of the time, only fragments are posted, usually with old versions referenced.
The project to use should be m2eclipse-scala
Enough with the problems: Here's a simple, complete, and hopefully up to date example (At least at the time of writing):
Use my github project minimal-scala-maven, to make sure the latest version,  otherwise this is also going to decay soon



It's using ScalaTest 2.0.M4 although is not a requirement. ScalaTest is going to be the an umbrella framework, capable of plugging other testing frameworks on top if need be. A Scala IDE plugin is well advanced too, so quite important. Beware, scalatest is supposed to provide a new maven plugin, so stay tuned.

This project should work well with latest 11.1.3 version of Intellij or Scala IDE 2.1 M2 (even tough the maven plugin will complain about lifecycle execution, compiles fine). This last bit I've managed to remove in the past, but I gave up trying to fix every issue. It requires Maven 3.

See some posts for other working approaches with older plugins

Let me know if it works for you, and you have any suggestions on improvement, in particular around Scala IDE.