sbt-eclipse icon indicating copy to clipboard operation
sbt-eclipse copied to clipboard

Create Eclipse projects for the SBT build and plugin projects

Open mkneissl opened this issue 13 years ago • 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.

mkneissl avatar Aug 30 '11 12:08 mkneissl

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

hseeberger avatar Aug 30 '11 16:08 hseeberger

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.

lalloni avatar Oct 04 '11 19:10 lalloni

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 ?

tonit avatar Nov 02 '11 18:11 tonit

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.

hseeberger avatar Nov 02 '11 18:11 hseeberger

mmhh.. just found this https://scala-ide-portfolio.assembla.com/spaces/sbt-builder-for-eclipse .. is this what i think it is ?

tonit avatar Nov 02 '11 18:11 tonit

heh.. somehow eclipse gets hold of it and does. I understand this is a glitch in eclipse. But it would be cool anyhow to get IDE support of the build file written in scala. Thinking more about it, it definitely would make sense if scalaIDE itself (as an eclipse plugin ) would get hold of it and provide fill support for editing this file.

On Wed, Nov 2, 2011 at 7:57 PM, Heiko Seeberger < [email protected]>wrote:

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.

Reply to this email directly or view it on GitHub: https://github.com/typesafehub/sbteclipse/issues/26#issuecomment-2607843

Toni Menzel Source http://tonimenzel.com

tonit avatar Nov 02 '11 19:11 tonit

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.

max-l avatar Nov 17 '11 21:11 max-l

This would be an awesome feature.

SandroGrzicic avatar Aug 21 '12 18:08 SandroGrzicic

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 avatar Sep 11 '12 22:09 cos

@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). :)

SandroGrzicic avatar Sep 11 '12 22:09 SandroGrzicic

+2 for supporting eclipse on sbt. Circular link back to one recipe for accomplishing this: https://groups.google.com/d/msg/simple-build-tool/zA27U9AoNSU/dikm32YWKQUJ

jkleckner avatar Sep 26 '12 22:09 jkleckner

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
sbt> 
  1. Go into Eclipse and modify the "Build Path". Remove src/main/* and add the root directory.
  2. clean and rebuild. VIOLA, eclipse support and boy is it good.

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

jsuereth avatar Oct 26 '12 16:10 jsuereth

Cool trick!

Already added: https://github.com/typesafehub/sbteclipse/wiki/Using-sbteclipse

hseeberger avatar Oct 26 '12 16:10 hseeberger

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

jkleckner avatar Oct 26 '12 18:10 jkleckner

+1

nafg avatar Jan 29 '13 07:01 nafg

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] = {
        //println(n)
    val result = n match {
    case e:Elem if(e.label == "classpathentry") => 
      if ((n \ "@kind" text) == "src") {
                if ((n \ "@path" text).startsWith("src/"))
                  Seq()
                else
                  Seq(n)
              } else
                Seq(n)

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

    //println("=> "+result)
    result
      }
    })
  }
})

}

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

ruediste avatar Feb 04 '13 19:02 ruediste

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

jsuereth avatar Apr 17 '13 11:04 jsuereth

Cool, this glitch/feature actually works, it's vital. @hseeberger Would it make sense to mention about the directory structure https://github.com/typesafehub/sbteclipse/wiki/Using-sbteclipse#eclipse-support-for-build-definition ?

rvvincelli avatar Aug 26 '15 14:08 rvvincelli