scalabeginner
SBT Build Configuration
Configure Scala projects with SBT: dependencies, plugins, multi-project builds, and custom tasks.
scalaPress ⌘/Ctrl + Shift + C to copy
// build.sbt - Main build file
// Project settings
lazy val root = (project in file("."))
.settings(
name := "my-scala-app",
version := "0.1.0",
scalaVersion := "3.3.1",
organization := "com.example",
// Compiler options
scalacOptions ++= Seq(
"-deprecation",
"-feature",
"-unchecked",
"-Xfatal-warnings",
"-explain"
),
// Dependencies
libraryDependencies ++= Seq(
// Core
"org.typelevel" %% "cats-core" % "2.10.0",
"org.typelevel" %% "cats-effect" % "3.5.2",
// JSON
"io.circe" %% "circe-core" % "0.14.6",
"io.circe" %% "circe-generic" % "0.14.6",
"io.circe" %% "circe-parser" % "0.14.6",
// HTTP
"com.softwaremill.sttp.client3" %% "core" % "3.9.1",
"com.softwaremill.sttp.client3" %% "circe" % "3.9.1",
// Database
"org.tpolecat" %% "doobie-core" % "1.0.0-RC4",
"org.tpolecat" %% "doobie-hikari" % "1.0.0-RC4",
"org.tpolecat" %% "doobie-postgres" % "1.0.0-RC4",
// Config
"com.typesafe" % "typesafe-config" % "1.4.3",
// Logging
"ch.qos.logback" % "logback-classic" % "1.4.11",
// Testing
"org.scalatest" %% "scalatest" % "3.2.17" % Test,
"org.scalacheck" %% "scalacheck" % "1.17.0" % Test,
"org.typelevel" %% "cats-effect-testing-scalatest" % "1.5.0" % Test
),
// Test settings
Test / fork := true,
Test / parallelExecution := true,
// Assembly settings
assembly / mainClass := Some("com.example.Main"),
assembly / assemblyMergeStrategy := {
case PathList("META-INF", _*) => MergeStrategy.discard
case _ => MergeStrategy.first
}
)
// Multi-project build
lazy val core = (project in file("core"))
.settings(
name := "core",
libraryDependencies ++= Seq(
"org.typelevel" %% "cats-core" % "2.10.0"
)
)
lazy val api = (project in file("api"))
.dependsOn(core)
.settings(
name := "api",
libraryDependencies ++= Seq(
"com.softwaremill.sttp.tapir" %% "tapir-core" % "1.9.2"
)
)
// project/plugins.sbt:
// addSbtPlugin("com.eed3si9n" % "sbt-assembly" % "2.1.4")
// addSbtPlugin("org.scalameta" % "sbt-scalafmt" % "2.5.2")
// addSbtPlugin("ch.epfl.scala" % "sbt-scalafix" % "0.11.1")
// addSbtPlugin("com.github.sbt" % "sbt-native-packager" % "1.9.16")
// Common SBT commands:
// sbt compile - Compile
// sbt test - Run tests
// sbt run - Run main class
// sbt assembly - Create fat JAR
// sbt clean compile - Clean and compile
// sbt "testOnly *Spec" - Run specific test
// sbt console - Open REPL with project classpath
// sbt dependencyTree - Show dependency tree
// sbt reload - Reload build definitionUse Cases
- Scala project setup
- Dependency management
- Multi-module build configuration
Tags
Related Snippets
Similar patterns you can reuse in the same workflow.
scalabeginner
Typesafe Config Parsing
Load and parse application configuration with Typesafe Config: HOCON format, defaults, and validation.
Best for: Application configuration management
#scala#config
scalabeginner
Scala Hello World Application
Create a basic Scala application with main method, string interpolation, and val/var basics.
Best for: Getting started with Scala
#scala#basics
scalabeginner
Pattern Matching Fundamentals
Use Scala pattern matching with guards, type patterns, tuple patterns, and nested extractors.
Best for: Control flow with pattern matching
#scala#pattern-matching
scalabeginner
Case Classes and Objects
Define immutable data with case classes: copy, equality, destructuring, and companion objects.
Best for: Domain modeling with immutable data
#scala#case-class