Koin Annotations 2.0 — Release is out!
Arnaud Giuliani on 2025-02-28
Koin Annotations 2.0 — Release is out!
A new major milestone for Kotlin Dependency Injection and Multiplatform!
Hello dear Koin community 👋

TL;DR:
Koin Annotations 2.0 is a major update for Kotlin dependency injection. Featuring a compiler rework with better stateless pass management — part of our KSP2 compatibility work — the update delivers a safer code extraction and generation engine that flawlessly handles annotation order and a reworked safety engine, ensuring smooth operation with both KSP1 and KSP2 and maximum speed. It brings multi-module support with @ComponentScan
extended capacity and package expressions, full Kotlin Multiplatform compatibility, and some impressive benchmarks. This release is powered by Google KSP 2.0.21-1.0.28, Kotlin 2.0.21, and Koin 4.0.2.
The evolution of Kotlin dependency injection has reached a major milestone with the launch of Koin Annotations 2.0. Designed from the ground up to meet the demands of modern, Kotlin multiplatform development, this release consolidates how annotations are handled in Kotlin projects. With a focus on efficiency, safety, and scalability, Koin Annotations 2.0 leverages a complete compiler rework to ensure that your projects are built faster and more reliably than ever before. Whether you’re working on large-scale multi-module applications or targeting both shared and native platforms through Kotlin Multiplatform, Koin Annotations 2.0 is built to handle it all with ease.
All release details can be found on Github: https://github.com/InsertKoinIO/koin-annotations/releases/tag/2.0.0
What’s New in Koin Annotations 2.0
Stateless Pass Management & Compiler Rework
- Part of KSP2 Compatibility: As part of our broader KSP2 compatibility work and compiler pass management rework, the compiler now utilizes stateless pass management. Each processing pass operates independently without carrying over unnecessary state. This redesign significantly boosts efficiency, minimizes errors, and allows smooth transition to symbol processing with KSP2.
- Robust and Safe Generation: The updated engine reliably handles annotation order in any scenario, ensuring safe and predictable code generation even in complex projects.
- Seamless KSP Compatibility: A complete rewrite of the “compile safety engine” guarantees smooth processing with both KSP1 and the latest KSP2, leveraging Google KSP 2.0.21–1.0.28 for modern symbol processing. Now you can use ksp.useKSP2=true in your gradle.properties file.
- KMP & Multi-Module Support: Now fully compatible with Kotlin Multiplatform projects, you can annotate both shared and native code, with definitions seamlessly shared across Gradle modules via enhanced
@ComponentScan
and package expressions.
- Sharing Effortless across Gradle Modules: Manage large codebases with robust multi-module support. Definitions are shared across Gradle modules effortlessly, simplifying the management of complex projects.
Benchmark Performance: The system can automatically split large definitions files as needed, and benchmarks demonstrate that generating and verifying 1650 definitions takes roughly 3 seconds.
Based on stable Kotlin stack:
Based on latest stable Kotlin stack:
- Google KSP: Powered by KSP 2.0.21–1.0.28
- Kotlin: Upgraded to Kotlin 2.0.21
- Koin: Now using Koin 4.0.2
Here’s what you can expect:
- ViewModel Definitions:
Tag your classes with annotations like
@Factory
,@Single
,@KoinViewModel
, or@KoinWorker
to follow Koin’s definition semantics. Automatic bindings are detected, so your extended types are added automatically (with the option to specify them if necessary).
- Automatic Binding: Definitions are created with automatic binding using the specified interface type.
- Qualifiers:
Use
@Named
for string qualifiers or@Qualifier
for type-based qualifiers. You can even create custom qualifiers by extending the@Qualifier
annotation.
- Kotlin Multiplatform Support:
All annotated definitions can be used in your Kotlin Multiplatform
commonMain
sourceSet, including@KoinViewModel
(with Compose ViewModel support).

Example: Inject your ViewModel in a Compose Multiplatform project.
Modules and Component Scanning
- Module Creation:
Annotate your classes with
@Module
to create a module. Definitions can be scanned using@ComponentScan
or declared as simple functions. Module scanning can span across all Gradle modules in your project.

- Native Components Sharing:
Share native components via an
expect/actual
contract. - Common Part: Define the contract in the common module.

- Native Implementation: Each platform (Android, iOS, etc.) provides its own module with the annotated native component.


- Just start your Module:
The Koin Compiler generates your Koin module as an extension, which you can easily load via the
startKoin
function.

Example: Just start your module with the generated .module
extension!
Performance and Safety
- Ready to Scale: Koin Annotations is designed to scale. For example, in a project with 1650 definitions, the compiler generates them in 2.5 seconds and verifies them in 1.7 seconds using KSP2 (it can split a too big definitions file).
- Compile Safety and Time Logging: Compile safety is optional — you can enable it if needed. Additionally, time logging can be activated to track build times.
Try out our getting started projects:
Upgrade now to harness the power of Koin Annotations 2.0 and experience next-level performance and flexibility in your projects.
Let us know what you think about this new release on koin slack channel or on twitter✌️