
Compile-time aspect-oriented weaving via compiler IR transformation, injecting @Aspect/@Before advice with zero runtime overhead; supports suspend, inline, extension, expect/actual functions, inheritance, many-to-many targets, rich JoinPoint metadata.
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.
// build.gradle.kts
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"
}@Target(AnnotationTarget.FUNCTION)
@Retention(AnnotationRetention.BINARY)
annotation class Loggedimport 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()})")
}
}@Logged
fun processOrder(orderId: String, amount: Double) {
// AspectK injects LoggingAspect.log() here at compile time
}| Feature | Details |
|---|---|
| Zero runtime overhead | Advice is woven at compile time — the generated code calls the advice function directly |
| Kotlin Multiplatform | JVM, Android, JS (IR), WASM/JS, Native Tier 1–3 |
| K2 IR powered | Built on the Kotlin 2.x IR transformation API |
| Many-to-many targeting | One @Before can list multiple target annotations; one function can match multiple aspects |
| Inheritance support |
@Before(inherits = true) intercepts overriding functions automatically |
| Rich join point metadata |
JoinPoint exposes receiver, method signature, parameters, annotations, and arguments |
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:
suspend functions — interception happens before coroutine lowering, so the advice sees the function in its original, unsuspended forminline functions — intercepted at the call site before the inliner runsexpect/actual functions across all platformsJVM · Android · JS (IR) · WASM/JS · macOS (arm64, x64) · iOS (arm64, sim, x64) · Linux (arm64, x64) · Windows (x64) · watchOS · tvOS · Android Native
Full documentation: https://mole-labs.github.io/aspectk/
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://www.apache.org/licenses/LICENSE-2.0
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.
// build.gradle.kts
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"
}@Target(AnnotationTarget.FUNCTION)
@Retention(AnnotationRetention.BINARY)
annotation class Loggedimport 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()})")
}
}@Logged
fun processOrder(orderId: String, amount: Double) {
// AspectK injects LoggingAspect.log() here at compile time
}| Feature | Details |
|---|---|
| Zero runtime overhead | Advice is woven at compile time — the generated code calls the advice function directly |
| Kotlin Multiplatform | JVM, Android, JS (IR), WASM/JS, Native Tier 1–3 |
| K2 IR powered | Built on the Kotlin 2.x IR transformation API |
| Many-to-many targeting | One @Before can list multiple target annotations; one function can match multiple aspects |
| Inheritance support |
@Before(inherits = true) intercepts overriding functions automatically |
| Rich join point metadata |
JoinPoint exposes receiver, method signature, parameters, annotations, and arguments |
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:
suspend functions — interception happens before coroutine lowering, so the advice sees the function in its original, unsuspended forminline functions — intercepted at the call site before the inliner runsexpect/actual functions across all platformsJVM · Android · JS (IR) · WASM/JS · macOS (arm64, x64) · iOS (arm64, sim, x64) · Linux (arm64, x64) · Windows (x64) · watchOS · tvOS · Android Native
Full documentation: https://mole-labs.github.io/aspectk/
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://www.apache.org/licenses/LICENSE-2.0