CLI
Libraries
Split code into reusable Gradle subprojects.
As an application grows, parts of it become reusable: a billing module used by the API and by a worker, shared data models, an internal client. A library is a Gradle subproject that holds such code, so several applications in the same repository depend on it.
kest g library billing-core # creates libs/billing-core, includes it in settings.gradle.kts, adds it to your buildshop/
settings.gradle.kts include(":libs:billing-core")
build.gradle.kts implementation(project(":libs:billing-core"))
libs/billing-core/
build.gradle.kts
src/main/kotlin/.../BillingCoreModule.kt a @Module
src/main/kotlin/.../BillingCoreService.kt an @InjectableA library is a Gradle subproject under libs/ with its own build.gradle.kts and sources. Put shared modules, entities and providers there and depend on them from any application in the repository:
// the app's build.gradle.kts
implementation(project(":libs:billing-core"))
ksp(project(":processor")) // the processor runs in the library too (its build file has it)
// the app's module
@Module(imports = [BillingCoreModule::class]) class AppModuleWhy libraries are good
- Boundaries Gradle enforces. An application can only use what the library exposes; internal classes can be
internal. - Faster builds. Gradle rebuilds only what changed.
- One place for shared rules, used by the API and the worker alike.
The processor works across projects, so the build-time wiring checks (visibility, cycles) include library modules.