I’ve been using Eclipse for a number of years now, and have been incorporating Maven as a build platform into my development projects. I recently started working with Scala and wanted to use the Scala IDE plugin (from http://www.scala-ide.org). I had some difficulty using using Eclipse Helios (3.6), Maven (specifically the M2Eclipse plugin), and the Helios version of the Scala IDE all together. Eclipse Helios and the Helios Scala IDE would work fine, but I would get errors in the project when it was a Maven project (as opposed to a straight Scala project). In order to get all three components to play nicely, I had to switch back to using Eclipse Ganymede (3.5) and the more stable version of the Scala IDE. Here’s how I set up my Eclipse environment.
- Install Eclipse Galileo SR2 for JEE development. Since I’m running on Linux, I use the 64-bit Linux version.
- Install M2Eclipse from http://m2eclipse.sonatype.org/sites/m2e
- Install SpringSource Tool Suite 3.5 from http://www.springsource.com/developer/sts (requires registration to get the Eclipse update directions). This is probably not strictly necessary, but since most of my projects involve Spring and Hibernate, STS gives you some nice tools for working in that environment. I found that if you are going to install STS, it needs to be done before installing the Scala IDE so you get the STS version of the JDT code weaving tools. If you try to install STS after Scala IDE, you’ll have the wrong version (and I couldn’t get them backed out).
- Install EGit from http://download.eclipse.org/egit/updates. Again, not strictly necessary, but it gives you some really nice local versioning, even if you’re not working with a remote Git repository.
- Install Scala IDE from the Eclipse Galileo update site (http://download.scala-ide.org/update-current-35) at http://www.scala-ide.org/. Don’t install the “JDT Weaving for Scala” component, since STS installs Aspect weaving.
Now, create a Maven project in Eclipse
- Open Eclipse and switch to the Scala perspective
- Create a Maven project for Scala:
- Select Ctrl-N to open the New dialog. Browse to ‘Maven’ and select ‘Maven Project’, and select ‘Next >’
- Select ‘Next >’ on the ‘New Maven Project’ dialog to accept the defaults
- Type ‘scala’ in the ‘Filter’ text field and select the ‘org.scala-tools.archetypes:scala-archetype-simple:1.3′ archetype. Select ‘Next >’
- Type a Group Id and Artifact Id. I selected ‘org.stupiphany’ and ‘ppa’, respectively.Select ‘Finish’ to create the project
- At this point, you will have a ‘ppa’ project, and it will contain some generated Scala code, but the project will still have a Java nature. Right-click on the project and select ‘Configure’ > ‘ Add Scala Nature’. The project icon should change from having a ‘J’ superscript to having an ‘S’ superscript. If you right-click on the project and select ‘Properties’ > ‘Builders’, you should see a ‘Maven project Builder’ and a ‘Scala Builder’, but no ‘Java Builder’.
- Now, open the pom.xml file, and note that you have an error message: “Missing artifact org.scalatest:scalatest:jar:1.2:test“. To solve this issue, we need to add a new Maven repository. Select the ‘Show Advanced Tabs’ icon at the top of the editor pan, and then select the ‘Repositories’ tab at the bottom. Select the ‘Create…’ button for the ‘Repositories’ list, and add a repository with an id of ‘org.scala-tools’ and a URL of ‘http://www.scala-tools.org/repo-releases‘. Save the file, and the error should go away.
- At this point, your project should compile and run fine. Try right-clicking on the App.scala file in src/main/scala, and selecting ‘Run As’ > ‘Scala Application’. You should see the results of running the application in the Console view.