Scala compiles to JVM bytecode. A build requires a Scala compiler at compile
time and the Scala standard library on the application runtime classpath.
Scala binary versions are compatibility boundaries: an artifact ending in
_2.13 is not interchangeable with its _3 counterpart.
Versions and Toolchains #
Scala 2 and Scala 3 have distinct compilers and language rules. Use the binary version selected by the project for every cross-published library. The Java runtime must meet the Scala release’s documented JDK requirements; compile and test with the JDK used in deployment.
For a small program:
scala-cli run Main.scala
scala-cli test .Scala CLI manages compiler and dependency resolution for source-oriented projects. Commit a build definition for maintained applications rather than depending on a developer’s local command history.
sbt #
sbt is Scala’s build tool. The launcher starts on the JVM and downloads the
sbt version declared by the project. Pin sbt in project/build.properties and
define the Scala version once:
ThisBuild / scalaVersion := "3.5.2"
ThisBuild / organization := "com.example"
lazy val root = (project in file("."))
.settings(
name := "orders",
libraryDependencies += "org.typelevel" %% "cats-core" % "2.12.0"
)Run sbt test, sbt compile, and sbt package from the project root. The
%% operator chooses the artifact suffix matching the active Scala binary
version. sbt itself can run on a different Scala version from the project;
the launcher uses the version required by sbt internals.
Coursier #
Coursier resolves JVM artifacts and installs Scala tools. It can launch an application by Maven coordinate, cache dependencies, and install a named command:
cs launch scala:3.5.2 -- -version
cs install scala-cliUse explicit application coordinates and versions in automation. Coursier’s cache improves repeatability only when coordinates and repositories are controlled; it does not replace dependency locking or artifact verification.
Coordinates, Repositories, and Channels #
Coursier reuses the Maven coordinate model and extends it for Scala-specific artifacts:
group:app:versionfor a Java application;group::app:versionfor a Scala artifact;group:::app:versionfor a cross-version Scala artifact.
It resolves dependencies from configured repositories, then downloads the artifacts into its local cache. Repositories can come from the command line, from a local directory, or from a channel descriptor source.
A channel is a collection of application descriptor JSON files. A channel may be served over HTTP, backed by a local directory, or packaged in a JAR file. That is why Coursier can discover installable apps without a handwritten build definition.
Launchers and Packaging #
Coursier installs executable launchers, not plain source trees. The installed
command is usually a script-prepended JAR: a small launcher script followed by
JAR bytes. The shell wrapper passes -J options to the JVM and then runs the
main class from the embedded application.
cs install scala-cli
cs launch scala:3.5.2 -- -versionThis packaging lets a user run ./tool directly while still keeping the JAR
format intact for java -jar. The practical tradeoff is that the launcher
still depends on the cached artifacts and on the chosen repository set.
Comments
Read or comment on GitHub (sign-in required to comment)