poniedziałek, 20 maja 2013

SetUp Scala development with Maven

To generate simple scala application by maven execute:

 mvn archetype:generate \
-DarchetypeGroupId=org.scala-tools.archetypes \
-DarchetypeArtifactId=scala-archetype-simple \ -DremoteRepositories=http://scala-tools.org/repo-releases \ -DgroupId=org.scala.test.app \
-DartifactId=TestScalaApp \

Scala stands for "Scalable Language". It is defined as a multi-paradigm programming language and has integrated support for object-oriented programming and functional programming. It runs on the JVM and on Android. It can read existing Java libraries which give it a huge advantage in cases where there is a lot of existing code infrastructure in Java.

Now we can look to generated code:
Simple Hello world App.scala:

package org.scala.test.app

object App {
  def foo(x : Array[String]) = x.foldLeft("")((a,b) => a + b)
  def main(args : Array[String]) {
    println( "Hello World!" )
    println("concat arguments = " + foo(args))


The pom.xml file is configured in a way that inntegrated the build lifecycle with Maven Scala plugin:


Compile  project: mvn compile
Run tests: mvn test

The generated pom.xml file contains Scala dependencies:




The first dependency is the Scala programming language, that is org.scala-lang.scala-library. The next two are for running Scala tests. The last one is for junit tests.

The last think what we will look on is the maven scala plugin. This are available goals and their explanations:
  • mvn scala:compile -Compile the Scala source directory
  • mvn scala:console - Launches the Scala REPL with all project dependencies
  • mvn scala:doc - Generates the documentation for all Scala sources
  • mvn scala:help - Displays the Scala compiler help
  • mvn scala:run - Executes a Scala class
  • mvn scala:script - Executes a Scala Scripts
  • mvn scala:testCompile - Compiles the Scala test sources

Brak komentarzy:

Prześlij komentarz