Click here to lend your support to: scala-maven-plugin and make a donation at www.pledgie.com !

Mixed Java/Scala Projects

Prerequisites : common usages

setup

Place java sources files in :

src/main/java

Place java test sources files in :

src/test/java

Place scala sources files in :

src/main/scala

Place scala test sources files in :

src/test/scala

Make your pom file look similar to the following (this is what we use for integration testing):

          
<?xml version="1.0" encoding="UTF-8"?>

<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>sandbox</groupId>
	<artifactId>testJavaAndScala</artifactId>
	<version>1.0-SNAPSHOT</version>
	<name>Test for Java + Scala compilation</name>
	<description>Test for Java + Scala compilation</description>

	<dependencies>
		<dependency>
			<groupId>org.scala-lang</groupId>
			<artifactId>scala-library</artifactId>
			<version>2.7.2</version>
		</dependency>
	</dependencies>

	<build>
		<pluginManagement>
			<plugins>
				<plugin>
          <groupId>net.alchim31.maven</groupId>
          <artifactId>scala-maven-plugin</artifactId>
          <version>3.1.7-SNAPSHOT</version>
				</plugin>
				<plugin>
					<groupId>org.apache.maven.plugins</groupId>
					<artifactId>maven-compiler-plugin</artifactId>
					<version>2.0.2</version>
				</plugin>
			</plugins>
		</pluginManagement>
		<plugins>
			<plugin>
        <groupId>net.alchim31.maven</groupId>
        <artifactId>scala-maven-plugin</artifactId>
				<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>
			<plugin>
				<groupId>org.apache.maven.plugins</groupId>
				<artifactId>maven-compiler-plugin</artifactId>
				<executions>
					<execution>
						<phase>compile</phase>
						<goals>
							<goal>compile</goal>
						</goals>
					</execution>
				</executions>
			</plugin>
		</plugins>
	</build>

</project>

          
       

Then use the standard maven phases :

          
# compile only
mvn compile
# or compile and test
mvn test
# or compile, test and package
mvn package