Scala
Completed
-
Section 1: Getting Started
-
Section 2: Core Syntax
-
Section 3: Object-Oriented Scala
-
Section 4: Functional Scala
-
Section 5: Collections in Depth
-
Section 6: Type System
-
Section 7: Concurrency and Ecosystem
-
Section 8: Practical Projects
-
Section 9: Interview Practice
-
Section 10: Data Structures and Algorithms in Scala
-
Section 11: More Practice Exercises
-
Section 12: Advanced Functional Patterns
-
Section 13: More Ecosystem
-
Section 14: Scala Collections Library Deep Dive
-
Section 15: Scala Standard Library Deep Dive
-
Section 16: Akka Ecosystem Deep Dive
-
Section 17: Cats and Cats Effect Deep Dive
-
Section 18: Play Framework Deep Dive
-
Section 19: Apache Spark with Scala Deep Dive
-
Section 20: Scala Build Tools Deep Dive
-
Section 21: Scala 3 Specific Features
-
90: Union and Intersection Types
-
Section 22: Scala Testing Deep Dive
-
Section 23: Functional Domain Modeling
-
Section 24: More Data Structures and Algorithms in Scala
-
Section 25: Scala for Data Engineering
-
Section 26: More Practical Projects
-
Section 27: More Interview and Review
-
Section 28: ZIO Ecosystem Deep Dive
-
Section 29: Scala for Machine Learning
-
Section 30: Scala Microservices Architecture
-
Section 31: Scala Type System Deep Dive
-
Section 32: More Practice and Drills
-
Section 33: Scala Performance Deep Dive
-
Section 34: Scala Ecosystem Tooling
-
Section 35: Scala for Reactive Systems
-
Section 36: More Real-World Case Studies
-
Section 37: Scala for Financial Systems
-
Section 38: Scala GraphQL and gRPC
-
Section 39: More Final Projects
-
Section 40: More Interview and Final Review
-
Section 41: Scala for Streaming Data
-
Section 42: Scala Security Practices
-
Section 43: More Language Deep Dive
-
Section 44: Scala Command-Line Tools
-
Section 45: Scala Documentation and Style
-
Section 46: Scala Dependency Management
-
Section 47: More Practical Backend Patterns
-
Section 48: Scala for Event-Driven Architecture
-
Section 49: More Practice Drills Round 2
-
Section 50: Scala Compiler Deep Dive
-
Section 51: Scala for Web Frontends
-
Section 52: More Data Engineering Practice
-
Section 53: Scala Observability
-
Section 54: More Advanced Practice Projects
-
Section 55: Scala for Legacy Java Integration
-
Section 56: More Testing Practice
-
Section 57: Final Mastery Review
-
Section 58: Scala History and Ecosystem Context
-
Section 59: More Concurrency Patterns
-
Section 60: Scala for Configuration Management
-
Section 61: More Domain Modeling Practice
34: Building with sbt Multi-Module Projects
I've noticed a recurring pattern with developers moving into larger Scala projects: they treat every logical separation of code as a reason to create a brand new, independent sbt project. You'll see a utils folder, a domain folder, and an api folder, each with its own build.sbt and its own separate lifecycle. When they want the api to use the domain, they start trying to publish local jars to Maven or manually tinkering with classpaths.
The "Separate Repository" Fallacy
The misconception is that "modular code" must equal "separate build projects." It doesn't. If you have three different projects that are always deployed together and developed by the same team, managing three separate build definitions is just overhead. You end up playing "version tag," where you update a method signature in the domain project, publish a snapshot, and then hope the api project picks up the change without a clean command.
It's a fragile way to work. You're adding friction to your inner loop—the time it takes to change a line of code and see the result. In reality, you want a single root project that orchestrates multiple sub-modules. This gives you the logical boundaries of separate projects but the developer experience of a single monolithic build.
Orchestrating Your Domain with Multi-Modules
Let's look at a real scenario. Imagine we're building a Payment Processing System. We need a payment-core module for the business logic, a payment-api for the REST endpoints, and a payment-cli for administrative scripts. We want the API and CLI to depend on Core, but Core should know absolutely nothing about how it's being called.
Instead of three folders with three build.sbt files, we use one root build.sbt. Here is how I would structure that:
lazy val commonSettings = Seq(
scalaVersion := "3.3.1",
organization := "com.paymentapp"
)
lazy val core = (project in file("core"))
.settings(commonSettings)
lazy val api = (project in file("api"))
.dependsOn(core)
.settings(commonSettings)
lazy val cli = (project in file("cli"))
.dependsOn(core)
.settings(commonSettings)
lazy val root = (project in file("."))
.aggregate(core, api, cli)
.settings(commonSettings)
Notice the aggregate call on the root project. This is a nuance that often trips people up. dependsOn tells sbt that the api needs the core classpath to compile. aggregate tells sbt that when I run compile or test from the root directory, it should trigger those tasks for all the aggregated projects too. Without aggregate, running compile at the root does... well, nothing, because the root project itself has no code.
Managing Dependencies without the Circular Headache
One thing I want to warn you about is the "circular dependency trap." As your project grows, you'll be tempted to let core depend on api just for one specific utility class. Don't. sbt will throw a fit, and more importantly, your architecture is rotting. If you hit a circular dependency in a multi-module build, it's a flashing red light telling you that you need a fourth module—perhaps payment-shared—that both core and api can depend on.
I also recommend using a commonSettings sequence as shown above. It keeps your build file dry. If you decide to upgrade your Scala version or add a common compiler plugin, you change it in one place rather than hunting through five different module definitions. It's a small detail, but it saves a lot of frustration during maintenance.
📋 Practical Task
Refactoring a Monolithic Order Management System into Modules
You have been handed a monolithic Scala project where the database logic, the business rules, and the JSON serialization are all mixed together in one folder. Your task is to refactor the sbt structure into a multi-module project to enforce a strict dependency hierarchy.
Requirements:
- Create a root
build.sbtthat manages three modules:order-model,order-persistence, andorder-web. - The
order-modelmodule should be the base (no dependencies on other internal modules). - The
order-persistencemodule must depend onorder-model. - The
order-webmodule must depend on bothorder-modelandorder-persistence. - The root project must be configured so that running
testat the root level executes tests for all three modules. - Extract shared settings (like
scalaVersionandorganization) into a common variable to avoid repetition.
Verification: Your solution is correct if you can run sbt compile from the root and it successfully compiles the modules in the correct order (Model → Persistence → Web) without any manual navigation into subdirectories.
There are no comments for now.