Maven: Mixed Projects with Java and Scala

Playing around with maven, scala and java I’ve found it useful to have both, java and scala, in one project. After searching for a while I’ve found several sources which helped me solving this point.

Everything which is needed is a standard quickstart project of maven. The folder structure has to be extended by the both directories:

src/main/scala
and
src/test/scala

After that you’ve got to add the following lines to the pom.xml of the maven project:

To use scala in the project you’ve got to add an additional repository:

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

Within the dependency-section you’ll need to add the needed library:

...
<dependencies>
<groupId>org.scala-lang</groupId>
<artifactId>scala-library</artifactId>
<version>2.9.0-1</version>
</dependencies>
...

After that I had to add the maven-scala-plugin to the build-lifecycle.

...

org.scala-tools
maven-scala-plugin

scala-compile-first
process-resources

add-source
compile

scala-test-compile
process-test-resources

testCompile

After that it was possible to use scala and java in one project (of course in diffrent directories).
Some other people put the maven-compiler-plugin below the maven-scala-plugin to define the order of execution.
If there are any Eclipse-Users outside: There is a m2e-scala connector which connects the lifecycle of the maven-scala-plugin to m2e. This makes the development on Eclipse much easier.

About these ads
This entry was posted in Java, Maven, Scala, Uncategorized. Bookmark the permalink.

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Connecting to %s