Getting Started – Maven Archetype for Scala

This is a two minute tutorial to get start with Scala development with Maven. Things are easy as there is a cool archetype to automate most of the project creation  .. ;-)

But first .. What is Scala? Here’s how Scala-lang.org defines it:

“Scala is a general purpose programming language designed to express common programming patterns in a concise, elegant, and type-safe way. It smoothly integrates features of object-oriented and functional languages, enabling Java and other programmers to be more productive. Code sizes are typically reduced by a factor of two to three when compared to an equivalent Java application.”

Let’s get started. First, you need Maven pre-installed and configured. If you don’t have it ready, stop right here.

Start the console and enter the following archetype:generate command:

$ mvn archetype:generate -DarchetypeGroupId=org.scala-tools.archetypes -DarchetypeArtifactId=scala-archetype-simple

This enters the interactive mode and asks you to enter the project groupId, artifactId, version and other project coordinates. After which it generates a Scala project.

This should have been it, but unfortunately it is not. You need to edit the generated pom.xml and uncomment the repositories and pluginRepositories elements.

<repositories>
<repository>
<id>scala-tools.org</id>
<name>Scala-Tools Maven2 Repository</name>
<url>http://scala-tools.org/repo-releases</url>
</repository>
</repositories>

<pluginRepositories>
<pluginRepository>
<id>scala-tools.org</id>
<name>Scala-Tools Maven2 Repository</name>
<url>http://scala-tools.org/repo-releases</url>
</pluginRepository>
</pluginRepositories>

Don’t ask me why they are commented in the first place, but as of March 5th 2011 they are and it sucks that they are.

By now we have avoided “dependency not found, build error”  and thankfully this is the only modification required.

You should now be able to successfully build the project..

$ mvn compile

..and get started with real programming.

4 thoughts on “Getting Started – Maven Archetype for Scala

  1. Pingback: Getting Started – Scala Persistence with Squeryl « Srirangan

  2. Pingback: Simple Database Migrations with Scala and Querulous « Srirangan

  3. Thanks for the tutorial. Everything I needed to know, nothing I didn’t :)

Leave a Reply

Your email address will not be published. Required fields are marked *

*

You may use these HTML tags and attributes: <a href="" title=""> <abbr title=""> <acronym title=""> <b> <blockquote cite=""> <cite> <code> <del datetime=""> <em> <i> <q cite=""> <strike> <strong>