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.15

Downloading: scala 2.13.15

In progress...

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

Installing: scala 2.13.15
Done installing!


Setting scala 2.13.15 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.4/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.4

Downloading: scala 3.3.4

In progress...

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

Installing: scala 3.3.4
Done installing!

Do you want scala 3.3.4 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.10.3

In progress...

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

Installing: sbt 1.10.3
Done installing!

Or you can install a specific version of sbt with

sdk install sbt 1.9.9

Downloading: sbt 1.9.9

In progress...

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

Installing: sbt 1.9.9
Done installing!

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

Setting sbt 1.9.9 as default.

Upgrade

Upgrade sbt can be done with

sdk upgrade sbt
Available defaults:
sbt (local: 1.9.9; default: 1.10.3)

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

Downloading: sbt 1.10.3

In progress...

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

Installing: sbt 1.10.3
Done installing!


Setting sbt 1.10.3 as default.

List sbt

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

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

================================================================================
+ - 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.9
setting sbt 1.9.9 as the default version for all shells.

scala-cli

Installation

sdk install scalacli

Downloading: scalacli 1.4.2

In progress...

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

Installing: scalacli 1.4.2
Done installing!


Setting scalacli 1.4.2 as default.

Upgrade

sdk upgrade scalacli
Available defaults:
scalacli (local: 1.4.2; default: 1.4.3)

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

Downloading: scalacli 1.4.3

In progress...

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

Installing: scalacli 1.4.3
Done installing!


Setting scalacli 1.4.3 as default.

Ammonite REPL

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

Try ammonite-repl

amm
Loading...
Welcome to the Ammonite Repl 3.0.0-M2 (Scala 2.13.14 Java 17.0.12)
@

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.2")
addSbtPlugin("ch.epfl.scala" % "sbt-scalafix" % "0.13.0")

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

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

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("org.typelevel" % "sbt-tpolecat" % "0.5.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.2.1")

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