SBT-Eclipse Integration

Yay, we finally have got a really good Eclipse plugin for Scala. Thanks to all the contributors for their great work (as a former Eclipse committer I know that it was hard work). But as lots of Scala projects use SBT as their build tool, a new need is arising, the need for an integration of SBT and Eclipse. For the last one and a half years or so I have been using SBT and IntelliJ IDEA, because the Scala plugin for IDEA is awesome and, most important, there is a really good SBT-IDEA integration. It is provided by the sbt-idea project which I take as an inspiring example for what I would like to achieve for SBT-Eclipse integration.

Therefore I started the sbteclipse project which aims at providing the same features as sbt-idea, i.e. the ability to create Eclipse project files (.project and .classpath) from an SBT project. As SBT will soon be on version 0.9 which differs a great lot from version 0.7 from a plugin developer’s perspective, I decided to develop sbteclipse as a plugin for SBT 0.9.

While there is still a very long way to go, I just released the very first version 0.1 of sbteclipse to the Typesafe repository which means that you can use it easily. Right now it will only create a single project with its source- and class-directories. Libraries and multi-module projects are not yet supported. And of course you will have to build SBT 0.9 on your own, because there are no binaries yet.

If you are interested, please take a look at the “Usage” section of the sbteclipse README. I would be glad to get your feedback, of course. Have fun!

SBT-Eclipse Integration

29 thoughts on “SBT-Eclipse Integration

  1. Hey Heiko,

    I agree that we need something as good as sbt-idea for Eclipse and I’m happy you’re already working on it (I intended to take a look at it once the Eclipse plugin for Scala gets support for the SBT 0.9 dependency manager as it’s a major requirement for me). Anyway, are you aware of https://github.com/musk/SbtEclipsify ?

    Best,
    Ismael

    1. Hey Ismael,
      Of course I know SbtEclipsify. First I thought about contributing, but as it only offers limited functionality (e.g. no multi-module projects) and is on SBT 0.7 which is very very different from SBT 0.9 I decided to take a fresh start.
      Heiko

      1. I see. This should also be good for sbt-idea as your work can serve as a template of how to make it work with SBT 0.9. Thanks for doing this. 🙂

        Best,
        Ismael

  2. This is really interesting! I really like sbt, but still hang on to Maven because of the great tool support in m2eclipse. Basically I’m a tool-sucker.

    What is the main difference between this project and the old sbt-eclipsify? (https://github.com/musk/SbtEclipsify) Will it only generate .project and .classpath files or are there any long time goals to have a full eclipse-plugin like m2eclipse? Is that what you mean with Multi-module projects?

    One of the features I really enjoy with m2eclipse is the ability to match a dependency with a project in the workspace. If I have project A depending on project B-SNAPSHOT in the pom, I could just check out project B-SNAPSHOT into the workspace and then my changes to B-SNAPSHOT will automatically be picked up in A after incremental compilation. I guess you would really need to hook into Eclipses classpath resolution for this to work right? Simply generating .classpath files wont be enough. Or am I missing something?

    I guess its the same difference as the mvn eclipse-plugin and m2eclipse I’m getting at.

    Anyway, keep up the good work, I would really like to get rid of Maven, but so far nothing beats the tooling of m2eclipse.

    1. Victor,

      The main difference between sbt-eclipse and SbtEclipsify is the SBT version. Then SbtEclipsify is more mature, but it also lacks support for multi-module projects which basically means that you can have more than one project and the projects are somehow related, i.e. there are project dependencies.

      Actually I am quite happy with the planned functionality and therefore I will probably not create something like m2eclipse. But maybe someone else will do so …

      Heiko

    2. “I guess you would really need to hook into Eclipses classpath resolution for this to work right? Simply generating .classpath files wont be enough. Or am I missing something?”

      No, this is not required.

      “I guess its the same difference as the mvn eclipse-plugin and m2eclipse I’m getting at.”

      mvn-eclipse-plugin supports workspace resolution. I used it with Java and Scala for a long time before we started using IDEA and SBT.

      Best,
      Ismael

      1. Ismael,

        okay, cool! I read up on this now because I never got mvn-eclipse-plugin to do anything for me. I guess it is because I always nested my multi-module projects and that doesn’t seem to be supported: http://maven.apache.org/plugins/maven-eclipse-plugin/examples/multi-module-projects.html

        Anyway, what I meant above was that m2eclipse is able to do workspace resolution without me even defining anything with modules. If my project is dependent on an open source project in a maven repo somewhere and I realize that I need to fix something over there, I can just clone the project from say github into my workspace and start working with it and changes are immediately picked up (if dep is snapshot). Can that really be done by generating .classpath files?

        Cheers,
        Viktor

    3. I am answering in the wrong place in the thread because it seems like there is a nesting limit or something (the “Reply” button is not available for the post I am answering).

      “If my project is dependent on an open source project in a maven repo somewhere and I realize that I need to fix something over there, I can just clone the project from say github into my workspace and start working with it and changes are immediately picked up (if dep is snapshot). Can that really be done by generating .classpath files?”

      Well, after you clone the other project into your workspace you have to run mvn eclipse:eclipse in your project (as usual with plugins that generate the configuration files). Once you do that, it will create a dependency to the project in your workspace if it’s a SNAPSHOT dependency.

      Best,
      Ismael

  3. Mikko Peltonen says:

    Heiko,

    This is just great news! I was just today thinking about creating something for Eclipse based on sbt-idea, but now I don’t have to 🙂 Also hearing that 0.9 differs quite a lot from 0.7 from plugin developer’s perspective was news to me (I haven’t followed the 0.9 development very much), so I can learn from your code when porting sbt-idea to 0.9.

  4. Eugene Ryzhikov says:

    I’m wondering if you thought about actual Eclipse plugin for SBT. The inspiration may be Maven m2eclipse plugin which IMO works really well. I think now Scala IDE requires really good SBT IDE.

    1. Eugene,

      As already mentioned in another reply I have no current plans for an Eclipse plugin. Let’s see how things evolve if/when sbt-eclipse has got all the features I would like to see, e.g. library dependencies and even multi-module projects. Let’s talk again then 😉

      Heiko

  5. Great work on the plugin Heiko!

    I have started working on an Idea plugin for 0.9 based on sbt-idea
    (https://github.com/teigen/plugins/blob/master/Idea.scala)
    The plugin supports single module project with compile and test scoped source, resource and dependencies.
    Its using Tasks instead of Commands (not sure of pros/cons yet) but is otherwise quite similar to sbt-eclipse.

    Currently the project is just my ~/.sbt/plugins folder, but it will be moved to a separate project soon (@Mikko – or preferably a branch on sbt-idea)

    /Jon-Anders

  6. Bob says:

    Hi Heiko

    I noticed that few folks have mentioned about a Scala Book that you have been authoring.
    If I could ask, which book is that? Has it been published?
    If not, can I get a chance to review the early draft?

    Bob

  7. Musk says:

    I just recently discovered this project and I must say I’m a bit dissapointed that you didn’t even attempt to contact me as the original author to collaborate on this and take Eclipsify to the next level…

    Is there any public repository where this project actually uses social coding or do I have to download the sources from the typesafe repositories in form of a jar?

    The github page is down and not accessible anymore

    Regards
    Stefan

    1. Manu,

      I am not sure what “creating WTP based” project means, but I don’t think so. It basically takes a SBT project and creates a “usual” Java project from it, taking the whole build path (source folders, target folders, project and library dependencies) into account. Of course a Scala nature is added to the project, but no “WTP nature” or something like that. But I hope that you can use the WTP tooling to convert such a Scala project into a WTP project in Eclipse.

      Heiko

  8. Mats says:

    Hi, I’m trying to use lift with eclipse. So I’ve been trying to set up a project using scala-2.9.0-1, lift-2.4-M2, sbt-0.10, sbteclipse-1.2 and xsbt-web-plugin-0.1.0. I can get a hello-world running using sbt jetty-run. Using sbteclipse I could also import the project nicely into eclipse (indigo).

    Now, how can I run it from inside eclipse? This is mainly important to enable debugging.

    1. Mats,

      Good to hear that sbteclipse worked for you. I am sorry, but I don’t know how to run Jetty inside of Eclipse. This is of course related to Eclipse and not to sbt, therefore you might ask you question in some Eclipse forums.

      Heiko

      1. Mats says:

        Not so “of course” to me. It’s related to sbt *and* eclipse, just as sbteclipse is. In the eclipse maven plugin for eclipse there is a way to “run as” / “maven build”. I thought there might be something similar for sbt. I think that would be pretty neat.

      2. Mats,

        Please see my answer to Hedefalk: sbteclipse is a “pure” sbt plugin and will always be.
        I agree, though, that an Eclipse plugin would be very nice.

        Heiko

      3. I agree with Mats that this would be a good feature. With m2eclipse you get maven options under run/debug so you can simply put jetty:run as target and debug away. The same would be nice with a sbt-plugin, to be able to run sbt commands from Eclipse run-configs.

        Mats, you should however be able to debug to an external application, right? So you can start your jetty outside of Eclipse with debugging turned on, and then do Debug -> Remote Java Application in Eclipse and simply enter the port the debug connection is at.

      4. Hedefalk,

        Sorry, but m2eclipse is an Eclipse plugin. sbteclipse, though, is a sbt plugin. Please don’t compare apples and pears.

        Heiko

      5. Heiko,
        yeah, sure, I’m just saying that would be a nice feature. Maybe not in sbteclipse though as you clearly stated above that you do not intend to do something like m2eclipse. It was not intentional to sound nagging if that was the case, I mostly just wanted to help Mats with an alternative, and the agreement part was just a pre-clause. Sorry about that.

Leave a reply to Mikko Peltonen Cancel reply