Scala environment recommendations? ("Programming in Scala")

Hi, welcome to the community and sorry for how difficult is the starting experience, especially related to tooling. But, everything from here is just way better, I promise!

Let me try to help you.

  1. Maybe the gitter channel is better for a newcomer, especially for this kind of question which are more interactive.
  2. Scala tooling can be divided into two groups: system-wide tools and project-specific tools; whenever to install system wide things depend on your preferences.
  • System-wide: I (and I would guess most people) have the following tools installed system-wide.
    • coursier: It is a small binary that helps to install and keep updated all the other tools in this list; check their home page and this video for details.
    • jdk: Since Scala main target is the JVM you need a jre to run most of your code and almost all tools in this list are actually jars; also I believe (but not sure) that the Scala compile requires a jdk.
    • sbtn (note the n at the end): A native launcher of sbt which is the default build tool in the Scala ecosystem, note this launcher will be used to download and execute the specific version of sbt that each of your project needs.
    • scala: (optional) I like to have a global Scala REPL and compiler for small snippets and experiments, but many people save this step due Ammonite (mentioned later).
    • ammonite: A more powerful REPL, which has things like a configurable set of default imports as well as the ability to import external libraries.
  • Project-wide: You only need one tool and it is your build tool, which will be in charge of downloading all your libraries / plugins including the Scala version, managing the classpath, compiling, testing and running your code; etc. The most common option is sbt which has a big plus over many other build-tools which is that your project can define the version of sbt it uses without needing additional extra wrappers or run scripts. You configure your project through a set of files:
    • build.sbt which contains things like your project name, organization and version; the Scala version (or versions if cross-compiling, but that is an advanced topic) to use, and your dependencies.
    • project/build.properties which is mainly used just to define your sbt version.
    • project/plugins.sbt (optional) which is used to add plugins to your build.

For example, a full hello world project that produces a fat jar that could be run by any JRE would be:

// file: build.sbt
name := "hello-world"
version := "1.0.0"
scalaVersion := "2.13.5"
assembly / assemblyJarName := "app.jar"

// file: src/main/scala/simple/Main.scala
package simple
object Main {
  def main(args: Array[String]): Unit = {
    println("Hello, World! - From: Scala")
  }
}

// file: project/build.properties
sbt.version=1.5.0

// file: project/plugins.sbt
addSbtPlugin("com.eed3si9n" % "sbt-assembly" % "0.15.0")

And then run:

sbtn assembly
java -jar targe/scala-2.13/app.jar
  1. About IDE, you can choose between IntelliJ and metals, metals supports any text editor with supports the LSP; for example VSCode. I also use WSL 2 and since VSCode has the external plugin, I can just launch code . in my terminal and it works out of the box. However, IntelliJ has more features than metals and it should provide a more out-of-the-box experience; however, if you launch VSCode in the directory with the files I mentioned before it should prompt you to import the project and that would be it.

Hope this helps!
Let me know if you have more questions!

3 Likes