I have the following (single) scala class
[ 14253 Oct 30 8:44] ./pom.xml
[ 9083 Oct 30 8:30] ./scaladem.iml
[ 102 Oct 29 19:21] ./src
[ 102 Oct 29 19:21] ./src/main
[ 102 Oct 29 19:21] ./src/main/scala
[ 102 Oct 29 19:21] ./src/main/scala/com
[ 102 Oct 29 19:21] ./src/main/scala/com/blazedb
[ 102 Oct 30 8:30] ./src/main/scala/com/blazedb/scalademo
[ 4646 Oct 30 8:30] ./src/main/scala/com/blazedb/scalademo/SDemo.scala
Here is the applicable section of the pom
<plugin>
<groupId>net.alchim31.maven</groupId>
<artifactId>scala-maven-plugin</artifactId>
<version>3.1.6</version>
<configuration>
<recompileMode>incremental</recompileMode>
<javacArgs>
<javacArg>-Xlint:unchecked</javacArg>
<javacArg>-Xlint:deprecation</javacArg>
</javacArgs>
</configuration>
<executions>
<execution>
<id>scala-compile-first</id>
<phase>process-resources</phase>
<goals>
<goal>add-source</goal>
<goal>compile</goal>
</goals>
</execution>
<execution>
<id>scala-test-compile</id>
<phase>process-test-resources</phase>
<goals>
<goal>testCompile</goal>
</goals>
</execution>
</executions>
</plugin>
When we run
mvn compile
We get (notice the 'no sources' ..)
[INFO] Scanning for projects...
[INFO]
[INFO] ------------------------------------------------------------------------
[INFO] Building SDemo 1.0
[INFO] ------------------------------------------------------------------------
[INFO]
[INFO] --- maven-compiler-plugin:2.3.2:compile (default-compile) @ scalademo ---
[INFO] No sources to compile
[INFO] ------------------------------------------------------------------------
[INFO] BUILD SUCCESS
[INFO] ------------------------------------------------------------------------
Update: when running the following command
$mvn scala:compile -DdisplayCmd=true
The compilation succeeds.
From suggestion of @badtrumpet I have added the explicit as shown below
<sourceDirectory>src/main/scala</sourceDirectory>
And this works even by mvn compile. But that would be an issue for mixed java/scala projects.
Here's an example (simple) pom.xml which I use as a bit of a boilerplate for Scala compilation and build using Maven:
<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/maven-v4_0_0.xsd">
<modelVersion>4.0.0</modelVersion>
<groupId>badtrumpet</groupId>
<artifactId>blog</artifactId>
<version>1.0-SNAPSHOT</version>
<inceptionYear>2013</inceptionYear>
<packaging>jar</packaging>
<properties>
<scala.version>2.10.2</scala.version>
<commons.codec.version>1.8</commons.codec.version>
<grizzled.version>1.0.1</grizzled.version>
<slf4j-log4j12.version>1.7.5</slf4j-log4j12.version>
</properties>
<repositories>
<repository>
<id>Sonatype repository</id>
<name>Sonatype's Maven repository</name>
<url>http://oss.sonatype.org/content/groups/public</url>
</repository>
<repository>
<id>scala-tools.org</id>
<name>Scala-Tools Maven2 Repository</name>
<url>http://scala-tools.org/repo-releases</url>
</repository>
<repository>
<id>milestone.repo.springsource.org</id>
<name>repo.springsource.org-milestone</name>
<url>https://repo.springsource.org/libs-milestone</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>
<dependencies>
<dependency>
<groupId>org.scala-lang</groupId>
<artifactId>scala-library</artifactId>
<version>${scala.version}</version>
</dependency>
<dependency>
<groupId>junit</groupId>
<artifactId>junit</artifactId>
<version>3.8.1</version>
<scope>test</scope>
</dependency>
<dependency>
<groupId>commons-codec</groupId>
<artifactId>commons-codec</artifactId>
<version>${commons.codec.version}</version>
</dependency>
<dependency>
<groupId>org.clapper</groupId>
<artifactId>grizzled-slf4j_2.10</artifactId>
<version>${grizzled.version}</version>
</dependency>
<dependency>
<groupId>org.slf4j</groupId>
<artifactId>slf4j-log4j12</artifactId>
<version>${slf4j-log4j12.version}</version>
</dependency>
</dependencies>
<build>
<sourceDirectory>src/main/scala</sourceDirectory>
<testSourceDirectory>src/test/scala</testSourceDirectory>
<plugins>
<plugin>
<groupId>org.scala-tools</groupId>
<artifactId>maven-scala-plugin</artifactId>
<executions>
<execution>
<goals>
<goal>compile</goal>
<goal>testCompile</goal>
</goals>
</execution>
</executions>
<configuration>
<scalaVersion>${scala.version}</scalaVersion>
</configuration>
</plugin>
</plugins>
</build>
<reporting>
<plugins>
<plugin>
<groupId>org.scala-tools</groupId>
<artifactId>maven-scala-plugin</artifactId>
<configuration>
<scalaVersion>${scala.version}</scalaVersion>
</configuration>
</plugin>
</plugins>
</reporting>
To add extra source folders to your maven project you can use the build-helper-maven-plugin.
So to add src/main/scala
as a source folder you would configure the following in your pom:
<plugin>
<groupId>org.codehaus.mojo</groupId>
<artifactId>build-helper-maven-plugin</artifactId>
<version>1.8</version>
<executions>
<execution>
<id>add-source</id>
<phase>generate-sources</phase>
<goals>
<goal>add-source</goal>
</goals>
<configuration>
<sources>
<source>${basedir}/src/main/scala</source>
</sources>
</configuration>
</execution>
</executions>
</plugin>
For a standard maven project this would mean that now both src/main/java
and src/main/scala
are considered source directories by maven.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With