Saturday, 9 April 2016

Scala and Maven

The usual dependency manager used in Scala projects is usually SBT. For some projects you may want to use good old maven. Below is how you can set up maven to build scala source files
Add the following repository to the pom to bring in scala libs:
<repositories>
  <repository>
    <id>scala-tools.org</id>
    <name>Scala-tools Maven2 Repository</name>
    <url>http://scala-tools.org/repo-releases</url>
  </repository>
</repositories>
Add the following repository to the pom to bring in scala libs:
<pluginRepositories>
   <pluginRepository>
      <id>scala-tools.org</id>
      <name>Scala-tools Maven2 Repository</name>
      <url>http://scala-tools.org/repo-releases</url>
    </pluginRepository>
</pluginRepositories>
Add the scala compiler to plugins section 
<!-- Scala compiler -->
<plugin>
    <groupId>net.alchim31.maven</groupId>
    <artifactId>scala-maven-plugin</artifactId>
    <version>3.2.2</version>
    <executions>
        <execution>
            <id>scala-compile-first</id>
            <phase>process-resources</phase>
            <goals>
                <goal>compile</goal>
            </goals>
        </execution>

        <execution>
            <id>scala-test-compile</id>
            <phase>process-test-resources</phase>
            <goals>
                <goal>testCompile</goal>
            </goals>
        </execution>
    </executions>
</plugin>
This all that is needed. By default you will put the java source files under src/main/java. This can be changed by specifying alternative source directory in the pom

No comments:

Post a Comment