A few short notes on converting SBT plugins to 0.10.x

I just finished converting my FindBugs SBT plugin findbugs4sbt to SBT 0.10.x.

FindBugs? What’s that? – Go have a look at its website, and then use it, always! One caveat though: It doesn’t support Scala source code. So use it with all your Java projects.

SBT? What’s that? – It’s a Scala-based build tool called “Simple Build Tool”, and it’s cool. Have a look at it and try it out!

Anyway, if you already know about SBT and think about moving over to the new 0.10.x version, or if you even think about hacking your own plugin for it (please do!), the following quick notes may be of interest to you…

  • Read the SBT wiki page about plugins first. It’s not perfect, but it’s a good start, and you could always help improving it.
  • SBT 0.10.x has changed so much that it’s a rewrite, mostly. Give up your hope of “simply converting” your plugin.
  • However, the new settings system seems well thought-out. Forget the trait- and override-based system of 0.7.x. You know you want to.
  • You want to take a look at this SBT source file. Believe me. You just don’t know yet that you do. Knowing the settings keys is absolutely vital for hacking plugins.
  • Take a good long look at all the existing plugins‘ source code. They’re all doing different things in different ways, and all in all, there’s a lot to learn from them.
  • Quick, learn the difference between SBT tasks and commands. In my humble opinion, task plugins are probably easier to write than command plugins.
  • Don’t be afraid to read and ask questions in the SBT Google Group.
  • Don’t use SBT 0.9.9. It’s the one slow version of SBT, and I used it for most of my plugin conversion, so that you don’t have to, too. :)
  • Please don’t put everything into one plugin source file. There are other people out there who want to learn how to create their own SBT plugins, and they want to be able to read and understand your code.
  • Browse the SBT API documentation and use the stuff that’s already in there. It’s a lot, even if it’s perhaps not so easy to find your way around in there (at least it hasn’t been for me).
  • Maybe, you want to consider comparing the sbt-0.7.x and the default branch of my findbugs4sbt plugin, if you want to convert something task-based and are after a “before” vs “after” comparison.

So there you have it, a few of my insignificant and unordered plugin conversion impressions. I hope you’ve had fun reading them.

Posted in Scala by jmhofer at June 7th, 2011.
Tags: , ,

5 Responses to “A few short notes on converting SBT plugins to 0.10.x”

  1. Heiko Seeberger says:

    “Please don’t put everything into one plugin source file.” <
    m + ” But in my case (sbteclipse) I really needed the locality of the state argument. No fun adding it to a lot of methods. Therefore I went for a single-method with local methods approach. Only works for one file, though.”
    }

  2. Heiko Seeberger says:

    Sigh, my nice little SBT-ish reply was reformatted by WordPress.

  3. Hi,
    I tried your plugin on a Scala-only project. While Scala appears to cause a few annoyances with FindBugs, it does work to some extent, since FindBugs analyses bytecode and not source code. It is extremely annoying to get 130 bug reports of which 7 are related to code I wrote, while 79 are coding-style warnings that make no sense for Scala and the rest are in compiler-generated code. But even those are somewhat interesting. For instance, I get “Non-transient non-serializable instance field in serializable class” which seems to point to a compiler bug (Scala closures cannot be actually serializable unless they only close on serializable objects).

Leave a Reply