sbt / sbt-eclipse

Plugin for sbt to create Eclipse project definitions
Apache License 2.0
716 stars 168 forks source link

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

Open mkneissl opened 13 years ago

mkneissl commented 13 years ago

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.

hseeberger commented 13 years ago

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

lalloni commented 13 years ago

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.

tonit commented 13 years ago

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 ?

hseeberger commented 13 years ago

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.

tonit commented 13 years ago

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

tonit commented 13 years ago

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 < reply@reply.github.com>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

max-l commented 12 years ago

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.

SandroGrzicic commented 12 years ago

This would be an awesome feature.

cos commented 12 years ago

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...

SandroGrzicic commented 12 years ago

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

jkleckner commented 12 years ago

+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

jsuereth commented 12 years ago

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> 

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?

hseeberger commented 12 years ago

Cool trick!

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

jkleckner commented 12 years ago

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

nafg commented 11 years ago

+1

ruediste commented 11 years ago

I did some further tweaking of the generated classpath:

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()) ) }

jsuereth commented 11 years ago

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

rvvincelli commented 9 years ago

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 ?