Kotlin
Completed
-
Section 1: Getting Started
-
Section 2: Core Syntax
-
Section 3: Null Safety
-
Section 4: Object-Oriented Kotlin
-
Section 5: Functional Kotlin
-
Section 6: Coroutines
-
Section 7: Collections Deep Dive
-
Section 8: Type System Deep Dive
-
Section 9: Interop and Tooling
-
Section 10: Kotlin DSLs and Patterns
-
Section 11: Testing and Quality
-
Section 12: Server-Side Kotlin
-
Section 13: Practical Projects
-
Section 14: Interview Practice
-
Section 15: More Practice Exercises
-
Section 16: More Standard Library
-
Section 17: Multiplatform Kotlin
-
Section 18: kotlin.collections In Depth
-
Section 19: kotlin.text In Depth
-
Section 20: kotlin.ranges and kotlin.sequences
-
Section 21: kotlin.io and File Handling
-
Section 22: kotlinx.coroutines Deep Dive
-
Section 23: kotlin.reflect
-
Section 24: Android Development with Kotlin Overview
-
Section 25: Kotlin Multiplatform Deep Dive
-
Section 26: Kotlin for Backend Deep Dive
-
Section 27: Kotlin Design Patterns
-
Section 28: Advanced Language Features
-
Section 29: More Practice Exercises
-
Section 30: More Interview Practice
-
Section 31: Kotlin Type System Deep Dive
-
Section 32: Kotlin Null Safety Advanced
-
Section 33: Kotlin Testing Deep Dive
-
Section 34: Kotlin Build Tooling Deep Dive
-
Section 35: Kotlin Serialization
-
Section 36: Kotlin Performance Considerations
-
Section 37: Kotlin Native Overview
-
Section 38: Kotlin for Data and Scripting
-
Section 39: More Coroutines Practice
-
Section 40: More Android-Adjacent Patterns
-
Section 41: More Practical Projects
-
Section 42: More Design and Architecture Practice
-
Section 43: Kotlin Language Evolution
-
Section 44: More Interview and Review
-
Section 45: Kotlin Delegation Patterns Deep Dive
-
Section 46: Kotlin Annotations Deep Dive
-
Section 47: Kotlin for Gradle Plugin Development
-
Section 48: Kotlin Concurrency Beyond Coroutines
-
Section 49: Kotlin Compiler Internals
-
Section 50: Real-World Kotlin Case Studies
-
Section 51: Final Practice Projects
-
Section 52: Kotlin for Server-Side Reactive Programming
-
Section 53: More Practice and Drills
-
Section 54: Kotlin Security Practices
161: Multi-Module Project Configuration
I've seen this play out in dozens of professional projects: a developer decides to modularize their Kotlin project and creates a single module called :common or :core. At first, it feels organized. But six months later, that :common module has become a "junk drawer." It contains everything from database entities and network wrappers to date formatting utilities and UI constants.
The misconception here is that modularization is about grouping "shared" code into one place. In reality, that approach creates a hidden monolith. If your :feature-login module depends on :common just to get a User data class, it's now also dragging in the entire Room database dependency and the Retrofit configuration from that same common module. You aren't actually decoupling your code; you're just moving the mess to a different folder. This kills your build times because a tiny change in a utility class triggers a re-compile of every single module in your app.
The "Put it in Common" Trap vs. Strategic Granularity
Instead of one giant core, you want to split your modules by responsibility and stability. Think about the "E-commerce" app we've been discussing in previous lessons. Instead of a :common module, we should split it into smaller, focused pieces:
:core-models: Just the POJOs/Data classes. No logic, no dependencies.:core-network: The OkHttp and Retrofit configuration.:core-database: The Room setup and DAOs.
Now, your :feature-catalog module can depend on :core-models and :core-network without ever knowing that a database even exists. This is how you actually achieve a fast build and a clean architecture.
Confusing 'implementation' with 'api' in Multi-Module Gradle
Once you have these modules, you'll run into a frustrating Gradle error: you've added a dependency to Module A, and Module A depends on Module B, but you can't access that dependency in Module B. You'll be tempted to just add the dependency to every single module. Don't do that.
The secret is the difference between implementation and api. When you use implementation, the dependency is private to that module. This is what you should use 90% of the time to keep your build graph lean.
// Inside :core-network build.gradle.kts
dependencies {
implementation("com.squareup.okhttp3:okhttp:4.12.0")
}
If :app depends on :core-network, it cannot see OkHttp. That's a good thing. But what if :core-network has a function that returns an OkHttp Response object? Now, :app needs to know what a Response is to call that function. This is where api comes in.
// Inside :core-network build.gradle.kts
dependencies {
// Now any module depending on :core-network also gets OkHttp transitively
api("com.squareup.okhttp3:okhttp:4.12.0")
}
I always tell my juniors: use implementation by default. Only switch to api if the library's types are part of the module's public interface (i.e., they appear in the return types or parameters of your public functions). If you use api everywhere, you're back to the "junk drawer" problem, where a version bump in one library forces the entire project to recompile.
📋 Practical Task
Refactoring a Monolithic 'Core' into Domain and Data Modules
You are working on a project with a bloated :core module. This module currently contains both the Product data model (which is used everywhere) and the ProductApi interface (which requires Retrofit). Your goal is to fix the dependency leak so that feature modules don't pull in Retrofit just to use the Product model.
Requirements:
- Create two new modules:
:core-domainand:core-data. - Move the
Productdata class into:core-domain. - Move the
ProductApiinterface and Retrofit implementation into:core-data. - Configure the
:core-databuild file to depend on:core-domainusingimplementation. - Configure the
:core-databuild file to useapifor the Retrofit dependency, as theProductApireturns RetrofitCallobjects. - Update the
:appmodule's dependencies so it depends on both:core-domainand:core-data.
Verification: Ensure that a class in :core-domain cannot import any Retrofit classes, while a class in :app can access both the Product model and the ProductApi.
There are no comments for now.