Blog

June 10, 2011

Integrating sbt and Eclipse

June 10, 2011

by Heiko Seeberger

Recently the revamped version 0.10 of the Simple Build Tool (sbt) was released. We are also closing in on a final 2.0.0 release of the Scala IDE for Eclipse that will hopefully bring the age of limited IDE support for Scala to an end. Having these two great tools at hand, we certainly need integration capabilities. The sbteclipse project aims at that very goal by providing a plugin for sbt that makes it possible to create Eclipse project files from an sbt project.

The current version 1.1 of sbteclipse, which requires sbt 0.10 or later, provides the additional sbt command eclipse which automatically creates Eclipse .project and .classpath files. Using the optional argument create-src will additionally create the source folders of the sbt project, e.g. src/main/scala. Of course this also works for multi-module projects. In such a case the root project often is just a folder and not a “proper” project. Therefore the optional argument skip-root can be given to prevent the Eclipse project files for the root project from being created.

As soon as the Eclipse project files are in place, the “Import...” wizard of Eclipse can be used to import “existing projects into workspace”. It is strongly recommended not to copy these projects into the workspace, i.e. simply leave the relevant checkbox unchecked. Otherwise the projects will be duplicated and possibly diverge on the long run.

In order to “install” sbteclipse as a general plugin which is available to all sbt projects, the following build.sbt file has to be created in the directory ~/.sbt/plugins:

resolvers += {
  val typesafeRepoUrl = new java.net.URL("http://repo.typesafe.com/typesafe/releases")
  val pattern = Patterns(false, "[organisation]/[module]/[sbtversion]/[revision]/[type]s/[module](-[classifier])-[revision].[ext]")
  Resolver.url("Typesafe Repository", typesafeRepoUrl)(pattern)
}

libraryDependencies <<= (libraryDependencies, sbtVersion) { (deps, version) => 
  deps :+ ("com.typesafe.sbteclipse" %% "sbteclipse" % "1.1" extra("sbtversion" -> version))
}

We hope that you find sbteclipse helpful and are looking forward to your comments. Please report any issues or enhancement requests via the project’s issue tracker.

comments powered by Disqus
Browse Recent Blog Posts