114

I am diving into Scala and noticed sbt. I have been quite happy with Gradle in java/groovy projects, and I know there's a scala plugin for Gradle.

What could be good reasons to favour sbt over Gradle in a Scala project?

7
  • SBT in some sense is like a Vim: if you grok it, you'll be pleased. And by the way, there is also maven and lein (was created for clojure, but works with scala too).
    – om-nom-nom
    Jun 16, 2012 at 11:52
  • 19
    Don't feel pressured to move to SBT. Some well known members of Scala community use Gradle. Instead, use SBT as an experiment, knowing you can just use Gradle instead. Jun 17, 2012 at 1:37
  • 6
    thanks all... Having read your insights, I'll stick with Gradle. It seems to me that that is where most build-tool efforts for the JVM space is going to be as we leave Maven behind. Jun 17, 2012 at 10:48
  • 11
    It is annoying that this question is being marked as 'opinion-based' here, probably by people who don't work in the JVM-space all the time (and therefore lacking the oversight). The answers below are factual and devoid of holy-war-ism's. Dec 15, 2015 at 11:00
  • 5
    No, those answers are primarily statements of testable facts, not opinions. While this question could attract unhelpful answers, it has not, in fact, done so. It should remain open as a useful description of actual differences between the tools.
    – erickson
    Apr 21, 2016 at 15:52

5 Answers 5

61

Note that one key difference between SBT and Gradle is its dependency management:

  • SBT: Ivy, with a a revision which can be given as a fixed one (1.5.2, for instance) or as latest (or dynamic) one.
    See "Ivy Dependency"
    That means the "-SNAPSHOT" mechanism support can be problematic, even though Mark Harrah details in this thread:

It is true the cache can get confused, but it is not true that Ivy doesn't understand resolving snapshots. Eugene explained this point in another thread, perhaps on the admin list. There is an issue with sbt's auto-update that was addressed in 0.12.

What Ivy does not support, as far as I know, is publishing snapshots in the manner Maven does. I believe I have stated this elsewhere, but if anyone wants to improve the situation, my opinion is that effort is best spent working with the Gradle team to reuse their dependency management code.

Just to let you know, problems with Ivy and Maven snapshot dependencies were one of the reasons why Gradle eventually replaced Ivy with its own dependency management code. It was a big task, but brought us a lot of goodness.

This tweet mentions that the all situation could evolve in the future:

Mark said in the past that he was interested in using Gradle instead of Ivy for SBT.

(both tools can learn from each other)

4
  • 1
    The most inconvenience I've ever met is sbt is that you could not specify for rule not to recompile each time it is mentioned. Built-in rules for java and scala have this functionality but it is not exposed for writing custom rules. So every time you generate a program file or documentation and even if you generate jar file your task would be performed on each call regardless of any changes to sources was actually done. Even make is smart enough, but not sbt
    – ayvango
    Jul 13, 2015 at 23:37
  • 1
    @ayvango It's not the case for nowadays sbt. There are many plugins which utilize this functionality, like android-sdk-plugin
    – dant3
    Nov 7, 2015 at 13:21
  • Do you know what API is used for that functionality?
    – ayvango
    Nov 7, 2015 at 15:01
  • so this is something ivy is lacking when comparing to both maven & gradle? That's strange
    – tribbloid
    Dec 23, 2018 at 23:45
53

For me the key features of SBT are:

  • Fast compilation (faster than fsc).
  • Continuous compilation/testing: the command ~test will recompile and test you project everytime you save a modification.
  • Cross-compilation and cross-publishing, across several scala versions.
  • Automatically retrieving dependencies with the correct scala version compatibility.

The downsides are:

  • A hieroglyphic syntax that tends to discourage new users (especially if they come from Java)
  • No easy way to define a "task": if you need a special build procedure, you will need to either find a plugin, or write a plugin yourself.
8
  • Am i correct that there is/was need for the cross-compilation/publishing feature due to the problems Scala has had with backwards binary incompatibility? Jun 16, 2012 at 17:26
  • 1
    Yes. And these problems may happen again when moving to Scala 2.10. Jun 16, 2012 at 17:39
  • 1
    There are two more differences I'd add: * In SBT, it's easier to self-manage dependencies, IMO. * The SBT test runner seems faster; I suspect there's some cunning concurrency involved here but I'm guessing. SBT seems like a more capable but rather less mature product.
    – Rick-777
    Jun 17, 2012 at 11:28
  • 25
    +1 for the 'hieroglyphic syntax' downside. That's my biggest gripe with SBT. Operator overloading always leads to abuse :-/
    – user1898811
    Apr 17, 2013 at 23:03
  • 7
    The cryptic SBT syntax brings out the worst in scala. Gradle is based on a well thought out domain model and straight forward syntax.
    – nemoo
    May 24, 2013 at 13:57
43

sbt is a Scala DSL and for it Scala is a first class citizen, so in principal it seems to be a good fit.

But sbt suffers from major incompatible changes between versions, which makes it hard to find the correct working plugin for a task and get it to work.

I personally gave up on sbt, since it was causing more problems than it solved. I actually switched to gradle.

Go figure.

9
  • 2
    As far, as I know, there was only one very major change: when sbt switched from 0.7.x to 0.1.x
    – om-nom-nom
    Jun 16, 2012 at 11:53
  • 1
    If you use a plugin for sbt 0.11.2, and then go to sbt 0.12, you need to wait for the plugin author to compile a new version or do it yourself. idea-sbt is one example.
    – fmpwizard
    Jun 16, 2012 at 13:15
  • 4
    @fmpwizard The sbt 0.12 line is not realeased yet... Stop spreading FUD. Jun 16, 2012 at 14:04
  • 3
    It's not the sbt is impossible to use, our team uses it. But my comment was to suport this answer, which said "...But sbt suffers from major incompatible changes between versions, which makes it hard to find the correct working plugin for a task and get it to work..." Like you notice, I cannot just use the scct plugin, I had to modify it (yes small change, but then I had to publish it somewhere so my whole team could access it) A pain for no good reason.
    – fmpwizard
    Jun 18, 2012 at 22:53
  • 3
    Are you able to do cross compilation for different Scala versions using gradle?
    – Machisuji
    Jul 28, 2014 at 8:59
5

I'm fairly new to gradle, and very new to sbt - what I really like about sbt so far is the interactive console. It allows me to use commands like 'inspect' to get a better idea of what's going on. AFAIK gradle does not provide something like this atm.

-13

Sbt and gradle, both are based on statically typed languages....but sbt has few advantages:

  • better plugin support, specially autoplugins
  • task creation and dependency management between tasks
  • sbt specially suits scala projects in the sense that it supports incremental builds and most of the sbt itself is written in scala and sbt build definitions is written in scala
  • sbt has interative shell support with many useful built-in tasks
  • sbt default lifecycle is pretty useful and can get novice started with pretty less effort
2
  • 2
    Gradle is based on groovy which is not statically typed language.
    – Vistritium
    Mar 15, 2016 at 14:39
  • Gradle does dependency management between tasks, it's as easy as possible to create a task, I have no idea how it can be easier to write a plugin than for gradle which can take groovy, Java, gradle plugins and possibly more.
    – Johnride
    Mar 21, 2016 at 18:28

Not the answer you're looking for? Browse other questions tagged or ask your own question.