Maven and Eclipse for Scala 2.9
These instructions were tested with the following versions.
- Maven 3.0.3
- Scala 2.9.1
- Eclipse 3.6.2 (Helios SR2)
- Sun’s Java 1.6.0_26
- Ubuntu 11.04 (Natty Narwhal)
Instructions:
Download Maven and install in
~/opt/apache-maven-3.0.3
.Create a Maven project with the Scala archetype.
$ JAVA_HOME=/usr/lib/jvm/java-6-sun ~/opt/apache-maven-3.0.3/bin/mvn archetype:generate -Dfilter=org.scala-tools.archetypes:scala-archetype-simple
Test compilation.
$ JAVA_HOME=/usr/lib/jvm/java-6-sun ~/opt/apache-maven-3.0.3/bin/mvn install
Update the POM to compile with Scala 2.9.1 rather than Scala 2.8.
diff --git a/pom.xml b/pom.xml index 6522932..417619d 100644 --- a/pom.xml +++ b/pom.xml @@ -18,7 +18,7 @@ <maven.compiler.source>1.5</maven.compiler.source> <maven.compiler.target>1.5</maven.compiler.target> <encoding>UTF-8</encoding> - <scala.version>2.8.0</scala.version> + <scala.version>2.9.1</scala.version> </properties> <!-- @@ -55,13 +55,13 @@ <dependency> <groupId>org.scala-tools.testing</groupId> <artifactId>specs_${scala.version}</artifactId> - <version>1.6.5</version> + <version>1.6.9</version> <scope>test</scope> </dependency> <dependency> <groupId>org.scalatest</groupId> - <artifactId>scalatest</artifactId> - <version>1.2</version> + <artifactId>scalatest_${scala.version}</artifactId> + <version>1.6.1</version> <scope>test</scope> </dependency> </dependencies>
Test compilation with Scala 2.9.
$ JAVA_HOME=/usr/lib/jvm/java-6-sun ~/opt/apache-maven-3.0.3/bin/mvn install
Update the POM to include Scala configuration for Maven’s Eclipse plugin.
diff --git a/pom.xml b/pom.xml index 7b17d81..ea26d11 100644 --- a/pom.xml +++ b/pom.xml @@ -110,6 +110,35 @@ </includes> </configuration> </plugin> + <plugin> + <groupId>org.apache.maven.plugins</groupId> + <artifactId>maven-eclipse-plugin</artifactId> + <version>2.8</version> + <!-- see http://maven.apache.org/plugins/maven-eclipse-plugin/eclipse-mojo.html for more information --> + <configuration> + <downloadSources>true</downloadSources> + <downloadJavadocs>true</downloadJavadocs> + <projectnatures> + <projectnature>org.scala-ide.sdt.core.scalanature</projectnature> + <projectnature>org.eclipse.jdt.core.javanature</projectnature> + </projectnatures> + <buildcommands> + <buildcommand>org.scala-ide.sdt.core.scalabuilder</buildcommand> + </buildcommands> + <classpathContainers> + <classpathContainer>org.scala-ide.sdt.launching.SCALA_CONTAINER"</classpathContainer> + <classpathContainer>org.eclipse.jdt.launching.JRE_CONTAINER</classpathContainer> + </classpathContainers> + <excludes> + <exclude>org.scala-lang:scala-library</exclude> + <exclude>org.scala-lang:scala-compiler</exclude> + </excludes> + <sourceIncludes> + <sourceInclude>**/*.scala</sourceInclude> + <sourceInclude>**/*.java</sourceInclude> + </sourceIncludes> + </configuration> + </plugin> </plugins> </build> </project>
Create Eclipse metadata for the project.
$ JAVA_HOME=/usr/lib/jvm/java-6-sun ~/opt/apache-maven-3.0.3/bin/mvn eclipse:eclipse
Download Eclipse 3.6.2 (Helios SR2) and install in
~/opt/eclipse-helios-SR2
.Start Eclipse.
$ ~/opt/eclipse-helios-SR2/eclipse&
Add the Scala 2.9 update site to Eclipse. ``` http://download.scala-ide.org/releases-29/stable/site
```
- Install Scala plugins from the update site:
* Scala IDE for Eclipse
* Scala IDE for Eclipse Source Feature
* JDT Weaving
Restart Eclipse to apply the new plugins.
Add a classpath variable for
M2_REPO
and set to~/.m2/repository
.Import the project.
Everything should compile and run correctly.
Useful pages:
- The Scala IDE website.
- The Scala IDE Getting Started guide.
- The Scala IDE guide to using Maven from the command line.
- Usage for the Maven Archetype plugin.