Wednesday 26 May 2010

Simple build configuration for Scala 2.8 with Maven

There are plenty of blogs explaining how to run Scala with Maven, but, unfortunately, many of them are out of them, no less the scala-lang website, which I will try to update with this simple recipe.

The good thing about this configuration, is that is tested with both Eclipse and IntelliJ Idea 9.0.2 (open source)




The directory structure remains the same as for java, with the obvious difference:

src/main/scala
src/test/scala

Finally, add your package and test it with a Canary Test




JUnit 4 + Hamcrest matchers seems like a very simple combination that will get the job done without dealing with the binary incompatibility problems of Scala before the final release of 2.8. It seems that jars need to be compiled against the exact version of the compiler or they won't work. I don't yet know enough about this problem, but was significant enough to drive me away of using the most recent versions of ScalaTest and Specs for now. Thus, I'm sticking to
2.8.0.RC1 which seems to work in all IDEs.

At the moment i'm using Intellij Idea 9.0.2, which comes with a pretty good Scala plugin. Eclipse is usually my IDE of choice, but the plugin is in an early stage yet, since doesn't support any refactorings.

Another rather annoying problem was with Hamcrest, which doesn't have the 1.2 version available in Maven Repositories, but it comes with some nice matchers some I recommend you to download it from their website. It seems that the High priority bug to deploy it in Maven Repo Central has been open for... 3 years! I added the 35th request to get it closed :) Otherwise, just switch to 1.1 version, which is available from Maven Central.


Enjoy!

No comments:

Post a Comment