Scala Development Environment
Coursier
If you haven't installed Coursier yet, install it first. (Coursier Installation)
Set up
Now, you can use Coursier to set up Scala development environment easily by just running the following command.
cs setup
The result may look like
Checking if a JVM is installed
Found a JVM installed under /Users/USERNAME/Library/Caches/Coursier/jvm/adopt@1.11.0-11/Contents/Home.
Checking if ~/Library/Application Support/Coursier/bin is in PATH
Checking if the standard Scala applications are installed
Installed ammonite
Found cs
Installed coursier
Installed scala
Installed scalac
Installed scala-cli
Installed sbt
Installed sbtn
Installed scalafmt
Different Java Versions
Would you like to install different Java versions? Check out the Java page.
Install Both Scala 2 and 3
If you want to have Scala 3 as well as Scala 2, you can install both Scala 2 and Scala 3 separately with the explicit scala3 names for the compiler and REPL.
Scala 2
Installation
Coursier installs Scala 3 by default, if you want to install Scala 2 (e.g. 2.13.11
), run
cs install scalac:2.13.11 scala:2.13.11
It installs both scalac
and scala
.
Scala 3
Now you can install Scala 3 with the scala3-
prefix.
Installation
cs install scala3-compiler scala3-repl
Update
cs update scala3-compiler scala3-repl
sbt
sbt plugins
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