Build Systems for Scala

Which build system should I use if I want to …

  1. learn Scala?
  2. use Scala in real-world projects?
  3. use Scala with other JVM languages?
  4. use Scala with C/C++/…?
  5. use Scala to build native applications (Scala Native / GraalVM)?
1 Like

Welcome to the Scala community, @oaf-0

  1. For learning you can just use scala-cli. From Scala 3.5.0 and onward, this comes installed with the language, and it’s simply scala. I recommend using VS Code with Metals extension. It’s dead simple to set it up, just run scala setup-ide . in the project root folder, then open it in VS Code. To add dependencies you can use using directives or collect all the directives in a single project.scala file.

Please do not learn from online tutorials / web searches. Use official learning materials. Beware of fake Scala courses. The Scala specialization on Coursera is done by the language creator.

  1. There are many tools for this. Scala-cli supports single-module projects only and acts as a versatile command-line tool rather than a full build tool. Sbt and Mill are the two most used in the Scala world. Sbt is very powerful but can be complex and has its own DSL to learn, Mill uses Scala code for build definition and it is fast. Scala-cli is made with Mill for example.

  2. Sbt can do this, Scala-cli and Mill support Java (and Mill is adding Kotlin support); but people also use other tools from the Java world like Maven, Gradle, Bazel etc.

  3. This one I have no idea. Scala Native has some support for C/C++ files but it’s not specific to a build tool. You would normally use Sbt for this.

  4. For Scala Native you can use Scala-cli (single module), Sbt or Mill. For GraalVM, Scala-cli can do it, I think Sbt can also do it with some plugin.

Generally try to stay with Scala-cli as far as you can, it’s super simple and can take you pretty far!

Hope it helps. Have fun! Drop by Scala Discord for live chat and faster support / feedback.

3 Likes

IMO after a project “graduates” scala-cli (which is indeed great for starting with, until you have multiple subprojects), the best build tool to graduate to is Bleep.

The build definition is a simple YAML file. Instead of SBT’s custom tasks or Mill’s custom targets, you write your build utilities exactly like other Scala code, and they can be integrated into the CLI too, in a manner reminiscent of the scripts property of a package.json for Javascript projects. And it’s way faster than SBT and Mill, including for its smooth IDE (BSP) support. (It’s built on top of Bloop and shares a lot of code with scala-cli, IIUC).

It definitely has room to improve, but IMO it’s well worth it given the tiny learning curve. (In particular, its YAML file uses a JSON schema so your IDE can tell you what’s valid and give documentation.)

1 Like

My answers would be

  1. scala-cli for easy stuff, mill for less easy stuff. With scala-cli you can just put build commands as comments at the top of the file. It doesn’t scale well, but wow is it easy! If you need help, get it working in scastie so people can play with the code you’re having trouble with.

  2. mill if you can, sbt if you must. Both are easy when things are trivial, but then you should be using scala-cli. mill is much easier to grok and configure. However, sbt has more extensions/plugins, so if a particular unusual capability is essential, you’ll likely use sbt

  3. If it’s Java, use mill. If Kotlin as well, probably gradle is your best bet right now, but mill is getting better Kotlin support soon, and sbt has a kotlin plugin. If others, I’m not sure, but probably gradle has the widest support right now for a more modern build system.

  4. Use whatever build system you like for C/C++ (probably some make variant?). Use that build system to call your Scala build system. As long as the two aren’t extremely tightly integrated, it works quite well. I have make running cargo and mill in a project that integrates C++, Rust, Scala, and Java, for example. Alternatively, if you’re really going all in on multi-language builds, you might want to use something like bazel. I’ve not yet found it necessary.

  5. mill or sbt should work fine, but if you’re just starting out with Scala, I’m not sure Scala Native is the easiest starting point. The biggest advantage of Scala Native is that it’s native and Scala. If you don’t know Scala, it loses its key advantage. So, unless the reason you’re learning Scala is that you need to support an existing Scala Native/C++ integration or something–at which point you should probably just adopt whatever is already being used–by the time you’re ready to worry about whether this is the right solution for the problem you’re facing, you’ll already know the answer yourself.

2 Likes