Rich Dougherty rd.nz

Maven and Eclipse for Scala 2.9

These instructions were tested with the following versions.

Instructions:

  1. Download Maven and install in ~/opt/apache-maven-3.0.3.

  2. 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
    
  3. Test compilation.

    $ JAVA_HOME=/usr/lib/jvm/java-6-sun ~/opt/apache-maven-3.0.3/bin/mvn install
    
  4. 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>
    
  5. Test compilation with Scala 2.9.

    $ JAVA_HOME=/usr/lib/jvm/java-6-sun ~/opt/apache-maven-3.0.3/bin/mvn install
    
  6. 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>
    
  7. Create Eclipse metadata for the project.

    $ JAVA_HOME=/usr/lib/jvm/java-6-sun ~/opt/apache-maven-3.0.3/bin/mvn eclipse:eclipse
    
  8. Download Eclipse 3.6.2 (Helios SR2) and install in ~/opt/eclipse-helios-SR2.

  9. Start Eclipse.

    $ ~/opt/eclipse-helios-SR2/eclipse&
    
  10. Add the Scala 2.9 update site to Eclipse. ``` http://download.scala-ide.org/releases-29/stable/site

```
  1. Install Scala plugins from the update site:
*   Scala IDE for Eclipse
*   Scala IDE for Eclipse Source Feature
*   JDT Weaving
  1. Restart Eclipse to apply the new plugins.

  2. Add a classpath variable for M2_REPO and set to ~/.m2/repository.

  3. Import the project.

  4. Everything should compile and run correctly.

Useful pages: