Skip to main content

Scala Development Environment

Installation

We will use SdkMan! to install Scala, so if you haven't installed SdkMan yet, install it first. (SdkMan Installation)

Install Scala 2

sdk install scala 2.13.12

Downloading: scala 2.13.12

In progress...

######################################################################### 100.0%

Installing: scala 2.13.12
Done installing!


Setting scala 2.13.12 as default.

Install Scala 3

warning

You may get an error like the following when you run scala 3 installed by sdkman.

/Users/USERNAME/.sdkman/candidates/scala/3.3.1/bin/common: line 33: /opt/local/bin/tput: Bad CPU type in executable
Exception in thread "main" java.lang.NumberFormatException: For input string: ""

If so, use Couriser to install Scala 3.

sdk install scala 3.3.1

Downloading: scala 3.3.1

In progress...

######################################################################### 100.0%

Installing: scala 3.3.1
Done installing!

Do you want scala 3.3.1 to be set as default? (Y/n): n

Different Java Versions

Would you like to install different Java versions? Check out the Java page.

sbt

Installation

You can install sbt with the following command.

sdk install sbt

Downloading: sbt 1.9.6

In progress...

######################################################################### 100.0%

Installing: sbt 1.9.6
Done installing!

Or you can install a specific version of sbt with

sdk install sbt 1.9.7

Downloading: sbt 1.9.7

In progress...

######################################################################### 100.0%

Installing: sbt 1.9.7
Done installing!

Do you want sbt 1.9.7 to be set as default? (Y/n): y

Setting sbt 1.9.7 as default.

Upgrade

Upgrade sbt can be done with

sdk upgrade sbt
Available defaults:
sbt (local: 1.9.6; default: 1.9.7)

Use prescribed default version(s)? (Y/n): y

Downloading: sbt 1.9.7

In progress...

######################################################################### 100.0%

Installing: sbt 1.9.7
Done installing!


Setting sbt 1.9.7 as default.

List sbt

You can get the list of all available and installed sbt with

sdk list sbt
================================================================================
Available Sbt Versions
================================================================================
> * 1.9.7 1.6.1 1.4.4 1.2.7
* 1.9.6 1.6.0 1.4.3 1.2.6
1.9.5 1.6.0-RC2 1.4.2 1.2.5
1.9.4 1.6.0-RC1 1.4.1 1.2.4
1.9.3 1.5.8 1.4.0 1.2.3
1.9.2 1.5.7 1.4.0-RC2 1.2.1
1.9.1 1.5.6 1.3.13 1.2.0
1.9.0 1.5.5 1.3.12 1.1.6
1.9.0-RC3 1.5.4 1.3.11 1.1.5
1.9.0-RC2 1.5.3 1.3.10 1.1.4
1.9.0-RC1 1.5.2 1.3.9 1.1.2
1.8.3 1.5.1 1.3.8 1.1.1
1.8.2 1.5.0 1.3.7 1.1.0
1.8.1 1.5.0-RC2 1.3.6 1.0.4
1.8.0 1.5.0-RC1 1.3.5 1.0.3
1.7.3 1.4.9 1.3.4 1.0.2
1.7.2 1.4.8 1.3.3 1.0.1
1.7.1 1.4.7 1.3.1 1.0.0
1.7.0 1.4.6 1.3.0 0.13.18
1.6.2 1.4.5 1.2.8 0.13.17

================================================================================
+ - local version
* - installed
> - currently in use
================================================================================

Set Default

If you have multiple sbts installed, you can set the default sbt manually by

sdk default sbt 1.9.6
setting sbt 1.9.6 as the default version for all shells.

scala-cli

Installation

sdk install scalacli

Downloading: scalacli 1.0.4

In progress...

######################################################################### 100.0%

Installing: scalacli 1.0.4
Done installing!


Setting scalacli 1.0.4 as default.

Upgrade

sdk upgrade scalacli
Available defaults:
scalacli (local: 1.0.4; default: 1.0.5)

Use prescribed default version(s)? (Y/n): y

Downloading: scalacli 1.0.5

In progress...

######################################################################### 100.0%

Installing: scalacli 1.0.5
Done installing!


Setting scalacli 1.0.5 as default.

Ammonite REPL

sh -c '(echo "#!/usr/bin/env sh" && curl -L https://github.com/com-lihaoyi/Ammonite/releases/download/3.0.0-M0/2.13-3.0.0-M0) > /usr/local/bin/amm && chmod +x /usr/local/bin/amm' && amm

Try ammonite-repl

amm
Loading...
Welcome to the Ammonite Repl 3.0.0-M0 (Scala 2.13.10 Java 17.0.8)
@

sbt plugins (Optional)

Global sbt plugins

You can set global sbt plugins by running the following command. Please choose the ones you want to have.

echo '
addSbtPlugin("io.github.todokr" % "sbt-project-switcher" % "0.1.4")
addSbtPlugin("com.timushev.sbt" % "sbt-updates" % "0.6.4")
addSbtPlugin("com.github.cb372" % "sbt-explicit-dependencies" % "0.3.1")

addSbtPlugin("org.scalameta" % "sbt-scalafmt" % "2.5.0")
addSbtPlugin("ch.epfl.scala" % "sbt-scalafix" % "0.11.0")

addSbtPlugin("net.vonbuchholtz" % "sbt-dependency-check" % "5.1.0")

addSbtPlugin("com.github.sbt" % "sbt-license-report" % "1.5.0")

addDependencyTreePlugin
' >> $HOME/.sbt/1.0/plugins/sbt-plugins.sbt

sbt-project-switcher

sbt-tpolecat

sbt-tpolecat is an SBT plugin for automagically configuring scalac options

Add the following line to project/plugins.sbt.

addSbtPlugin("io.github.davidgregory084" % "sbt-tpolecat" % "0.4.2")

sbt-wartremover

WartRemover is a linting tool that can help you write safe and correct code.

Add the following line to project/plugins.sbt.

addSbtPlugin("org.wartremover" % "sbt-wartremover" % "3.1.3")

In build.sbt,

wartremoverErrors ++= Warts.all

Or more practical settings might be

wartremoverErrors ++= Warts.allBut(Wart.Any, Wart.Nothing, Wart.ImplicitConversion, Wart.ImplicitParameter)

Also add the following setting to exclude the source code generated by build from wart checking.

wartremoverExcluded += sourceManaged.value