Create Eclipse projects for the SBT build and plugin projects #26

mkneissl opened this Issue Aug 30, 2011 · 18 comments

To be able to edit the SBT build definition from within Eclipse with full support, it would be useful to have a project generated for the project and project/plugins directories, too.


Currently I consider this out of scope, but will keep it around as a feature request.


This would be a really nice tool to have...

I've been using gen-idea for intellij idea and it do just that, then when I'm back on eclipse+sbteclipse I really miss that feature, so bad that I ended up simulating it by hand... creating a new eclipse project inside /project and adding sbt-main jar by hand to its classpath.

Of course a couple of things must be thought, idea is great for nesting "modules", so you just "mount" the "project" dir as a new module, in eclipse I guess a new project named "-project" or "-sbt" will need to be created pointing to /project, add sbt libraries to its classpath, etc.


Out of Scope ?? .. Heiko!!! Think!! ;)

I actually found it quite stupid editing a .scala source file in scalaIDE without any IDE support. Its even worse, scalaIDE detects this Build.scala as a scala source file and consequently shows errors within the editor. Quite annoying.
Idea adds the sbt libraries to a specific scope, done.
Yeah, as plalloni says, its a question how to implement this in Eclipse.
One way is to not create another project but just add "build" folder to the sources and add sbt libraries. One could think of an option to generate this special "sbt" support, so you simple to disable (or not enable by default). The major drawback is that you pollute the eclipse build path with dependencies you usually would not have.
What i would not like: another project in eclipse for each SBT build. Since those build projects can be nested, god knows what you'll get on an average sized project with many (regular) submodules.

Another thing could be "native" support by the scalaIDE plugin. So not just generating "stupid" .classpath files but ClasspathContainers that add much more flexibility. Basically just like its done in m2eclipse for maven.

But i'm sure typesafe is working on this.. ;) On the other hand i would like to know how you (Heiko) actually work with this tool chain we currently have. Simply use VI for editing Build.scala ?


You wrote: "Its even worse, scalaIDE detects this Build.scala as a scala source file and consequently shows errors within the editor"

That does not happen for me. Build.scala is in the project directory which by default should not be an Eclipse source folder.


mmhh.. just found this .. is this what i think it is ?


This feature would be highly useful.
Editing the Build.scala file is just a pain right now, granted that it would make most sense for Scala IDE
to provide edit support just like any scala source file, but making the eclipse sbt plugin generate a project
would be very, very usefull.


This would be an awesome feature.


Struggling with exactly this right now. The obvious path of just "sbt eclipse"-ing the project folder does not work. I've added Build.scala to the classpath but this pops up lots of errors as it is missing the sbt library. The next step is adding the sbt library manually to eclipse...


@cos My plugin, unrelated to this one, SBT Console for Scala IDE, actually does that for you, when you edit a SBT build file in the project folder and enable the relevant feature in the options. It's a bit experimental, though (the feature - the console itself works great, imho). :)


+2 for supporting eclipse on sbt. Circular link back to one recipe for accomplishing this:


Here's how you can accomplish this:

1) Install sbteclipse as a global plugin ( ~/.sbt/plugins/eclipse.sbt)
2) Do this in SBT

sbt>  reload plugins
sbt> eclipse

3) Go into Eclipse and modify the "Build Path". Remove src/main/* and add the root directory.
4) clean and rebuild. VIOLA, eclipse support and boy is it good.

Heiko - Can we add this to the documentation, and if so, where?


Nice! Note that if you are using Paul Phillips' script, it would go into ~/.sbt/0.11.3/plugins for example.




I did some further tweaking of the generated classpath:

  • remove all default source directories
  • add just the root directory

Could this functionality (not that ugly code of course) be added to the plugin itself?

import sbt._
import Keys._
import com.typesafe.sbteclipse.plugin.EclipsePlugin.EclipseKeys

object LpfBuildBuild extends Build {
private def createT() = {
import com.typesafe.sbteclipse.plugin.EclipsePlugin.EclipseTransformerFactory
import com.typesafe.sbteclipse.core._
import scala.xml.transform.RewriteRule
import scala.xml.Node
import scala.xml.Elem

EclipseKeys.classpathTransformerFactories := Seq(new EclipseTransformerFactory[RewriteRule] {
  override def createTransformer(project: sbt.ProjectRef, state: sbt.State): Validation[RewriteRule] = {
    scalaz.Success(new RewriteRule {
      var rootEmitted = false
      override def transform(n: Node): Seq[Node] = {
    val result = n match {
    case e:Elem if(e.label == "classpathentry") => 
      if ((n \ "@kind" text) == "src") {
                if ((n \ "@path" text).startsWith("src/"))
              } else

            case e:Elem if(e.label == "classpath") =>
        { e.child}
        <classpathentry including="*.scala" kind="src" path=""/>

    //println("=> "+result)


lazy val lpfBuild = Project(
id = "lpf-build",
base = file(".") ,
settings = Defaults.defaultSettings ++ Seq(createT())


Nice fix! I'd love to get this more "default" out of thofbox friendly...


Cool, this glitch/feature actually works, it's vital. @hseeberger Would it make sense to mention about the directory structure ?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment