Skip to content

Instantly share code, notes, and snippets.

@witt3rd
Last active April 18, 2021 14:08
Show Gist options
  • Save witt3rd/e0aa245bcce6c2f0e4a16d4a504e6fa9 to your computer and use it in GitHub Desktop.
Save witt3rd/e0aa245bcce6c2f0e4a16d4a504e6fa9 to your computer and use it in GitHub Desktop.
Scala installation, setup, and usage notes

Scala

Install

Installers

These CLI utilities are used to fetch things we need.

Java

We need a JDK, which SDKMAN is used for.

# List available JDKs
sdk ls java

Amazon seems to have a high-quality one.

Version 11 is the last LTS version.

sdk i java 11.0.10.9.1-amzn

Build

sbt

sdk i sbt 1.5.0

Bloop

A system-wide build server that speeds compile times and can watch for changes and automatically recompile.

cs install bloop --only-prebuilt=true

New Project

Create a new Scala 3 project using the following template:

sbt new scala/scala3.g8

Change into your project directory and compile and run it using sbt.

sbt compile
sbt run

SBT Plugins

The following plugins can be added to project/plugins.sbt to enhance the Scala coding experience.

Code Formatting

cs install scalafmt
addSbtPlugin("org.scalameta" % "sbt-scalafmt" % "2.4.0") // "2.4.0" is just sbt plugin version

Metals should automatically create a .scalafmt.conf file in the project root. My settings:

version = "2.7.4"
align.preset = more
maxColumn = 100

better-monadic-for

| A Scala compiler plugin to give patterns and for-comprehensions the love they deserve.

addCompilerPlugin("com.olegpy" %% "better-monadic-for" % "0.3.1")

IDEs

VS Code

This extension will install everything it needs

Watch, Compile, and Run

Use Bloop to watch for changes and automatically compile and run your program. Your project should have a .bloop directory that contains a <project>.json, <project>-test.json, and a <project> subdirectory. (Metals in VS Code will create this automatically.) If it doesn't exist, you'll need to use bloop project to create one.

In one terminal session from within your project's root directory (the one that contains .bloop), run:

bloop compile -w <project>

From another terminal (same directory), run:

bloop run -w <project>

Project Scaffolds

Language

Ecosystem

ZIO

Misc

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment