AspectK
Compile-time Aspect-Oriented Programming for Kotlin Multiplatform.
AspectK is a Kotlin compiler plugin that injects advice code at compile time via K2 IR transformation —
no runtime reflection, no proxies, zero overhead. Declare an @Aspect, annotate your advice with @Before,
and AspectK weaves the call directly into the intercepted functions during compilation.

Quick Setup
1. Apply the Gradle plugin
plugins {
id("io.github.mole-labs.aspectk") version "LATEST_VERSION"
}
For Kotlin Multiplatform:
plugins {
kotlin("multiplatform")
id("io.github.mole-labs.aspectk") version "LATEST_VERSION"
}
2. Define a target annotation
@Target(AnnotationTarget.FUNCTION)
@Retention(AnnotationRetention.BINARY)
annotation class Logged
3. Create an aspect
import io.github.molelabs.aspectk.runtime.Aspect
import io.github.molelabs.aspectk.runtime.Before
import io.github.molelabs.aspectk.runtime.JoinPoint
@Aspect
object LoggingAspect {
@Before(target = [Logged::class])
fun log(joinPoint: JoinPoint) {
println("→ ${joinPoint.signature.methodName}(${joinPoint.args.joinToString()})")
}
}
4. Annotate your functions
@Logged
fun processOrder(orderId: String, amount: Double) {
}
Features
Supported Function Types
AspectK works with the full range of Kotlin function kinds — including those that other AOP
solutions struggle with. Because advice is injected during the IR transformation phase,
before platform-specific lowering, AspectK intercepts functions exactly as Kotlin defines them:
- Class member functions
- Top-level functions
- Extension functions
suspend functions — interception happens before coroutine lowering, so the advice sees the function in its original, unsuspended form
- — intercepted at the call site before the inliner runs
Supported Platforms
JVM · Android · JS (IR) · WASM/JS · macOS (arm64, x64) · iOS (arm64, sim, x64) · Linux (arm64, x64) · Windows (x64) · watchOS · tvOS · Android Native
Documentation
Full documentation: https://mole-labs.github.io/aspectk/
License
Copyright 2026 Mole Labs
Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
You may obtain a copy of the License at
https: