Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Pros and cons of using sbt vs maven in Scala project [closed]

Tags:

maven

scala

sbt

Which build tool is the best for Scala? What are the pros and cons of each of them? How to I determine which one of them to use in a project?

like image 408
Konstantin Solomatov Avatar asked Sep 27 '22 17:09

Konstantin Solomatov


People also ask

Is sbt better than Maven?

I recently surveyed the current state of these three tools and concluded that SBT is better suited than Maven to Scala projects' needs.

Why do we need sbt in Scala?

Besides managing your project, some build tools, including sbt, can automatically manage dependencies for you. This means that if you need to use some libraries written by others, sbt can automatically download the right versions of those libraries and include them in your project for you.

Can Maven be used for Scala?

Think back to “convention over configuration”; in our case, the Scala Maven Plugin provides an archetype for scala projects. If this is your first time, you'll notice that Maven is downloading many jar files. Maven resolves dependencies and downloads them as needed (and only once).

Does sbt require Scala?

sbt needs Scala jars to run itself since it is written in Scala. sbt uses that same version of Scala to compile the build definitions that you write for your project because they use sbt APIs. This version of Scala is fixed for a specific sbt release and cannot be changed.


2 Answers

We're using Maven to build Scala projects at work because it integrates well with our CI server. We could just run a shell script to kick off a build, of course, but we've got a bunch of other information coming out of Maven that we want to go into CI. That's about the only reason I can think of to use Maven for a Scala project.

Otherwise, just use SBT. You get access to the same dependencies (really the best part about maven, IMHO). You also get the incremental compilation, which is huge. The ability to start up a shell inside of your project, which is also great.

ScalaMock only works with SBT, and you're probably going to want to use that rather than a Java mocking library. On top of that, it's much easier to extend SBT since you can write full scala code in the build file, so you don't have to go through all the rigamarole of writing a Mojo.

In short, just use SBT unless you really need tight integration into your CI server.

like image 91
mblinn Avatar answered Oct 16 '22 13:10

mblinn


The question is in danger of just generating lots of opinions; it would be better to have a clear list of requirements or a description of your environment, previous knowledge, etc.

FWIW, there are more opinions in this scala mailing list thread.

My 2c are: Go with sbt if you don't have specific requirements

  • for simple projects, it's totally effortless (you don't even need a build file until you have dependencies)
  • it is commonly used across Scala open source projects. You can easily learn about configuration by peeking into other people's projects. Plus many projects assume you use sbt and provide you with ready-made copy+paste instruction for adding them as a dependency to your project.
  • if you use IntelliJ IDEA, it can be totally integrated. You can have IDEA use sbt to continuously compile your project, and vice versa you can use sbt to quickly generate IDEA projects. The last is extremely useful if you are in a 'snapshot' cycle with depending on other of your own libraries which are bumped from minor version to minor version -- just close the project, update the version in the build file, re-run the gen-idea task, and re-open the project: updates done.
  • comes ready with most tasks you will need (compile, test, run, doc, publish-local, console) -- the console is one of the best features.
  • some people highlight the feature that dependencies can be source repositories directly grabbed from GitHub. I haven't used this so can't comment here.

Some people hate sbt because it uses Ivy for dependency management (I can't comment on its pros and cons, but most of the time it is a non-issue), some people hate sbt because you specify the build file in terms of a Scala DSL instead of XML. Some people were disappointed that sbt's format changed from v0.7 to v0.10, but obviously, migration won't affect you if you start from scratch.

like image 21
0__ Avatar answered Oct 16 '22 14:10

0__