Sunday, June 12, 2011

IntelliJ IDEA for Scala/SBT projects

I have found it easier to use Intellij IDEA with Scala plugins, for Scala learnings. This is the way I normally spin up a scala project.

1. Use sbt to first create a shell of a project:

D:\learn\shell-project>set SCRIPT_DIR=C:\util\sbt\

D:\learn\shell-project>java -Xmx512M -jar "C:\util\sbt\sbt-launch-0.7.5.jar"
Project does not exist, create new project? (y/N/s) y
Name: shellproject
Organization: org.bk

2. Add eclipsify plugin - this is done by creating a sbt ProjectDefinition under project/plugins folder:
import sbt._

 class MySbtProjectPlugins(info: ProjectInfo) extends PluginDefinition(info) {
       lazy val eclipse = "de.element34" % "sbt-eclipsify" % "0.7.0"

3. Add scalatest to the dependency - this is done by creating a file of the following type under project/build folder:

import sbt._
import de.element34.sbteclipsify._

class MySbtProject(info: ProjectInfo) extends DefaultProject(info) with Eclipsify {
    override def libraryDependencies = Set(
       "org.scalatest" % "scalatest" % "1.3" % "test->default"
    ) ++ super.libraryDependencies

4. reload sbt(run "reload" in the sbt console)

5. A new action "eclipse" should now be available. Run "eclipse"

6. That's it. Now a new project should be available for IntelliJ idea to import as a project.

No comments:

Post a Comment