Skip to content

Plugin Configuration

Complete reference for configuring the Fakt Gradle plugin.


Complete Configuration Reference

All available configuration options in your module’s build.gradle.kts:

// build.gradle.kts
import com.rsicarelli.fakt.compiler.api.LogLevel

plugins {
    alias(libs.plugins.fakt)
}

fakt {
    // Enable or disable the plugin (default: true)
    enabled.set(true)

    // Control logging verbosity (default: INFO)
    logLevel.set(LogLevel.INFO)  // Options: QUIET, INFO, DEBUG

    // Control call history generation (default: true)
    enableCallHistory.set(true)  // Set to false for lightweight fakes

    // Control mutable fake generation (default: false)
    enableMutableFakes.set(false)  // Set to true for mutable fakes by default

    // Generate fakes to testFixtures source set (default: false, JVM only)
    useGradleTestFixtures.set(false)  // Requires `java-test-fixtures` plugin

    // Multi-module: Collect fakes from another module (default: not set)
    @OptIn(com.rsicarelli.fakt.compiler.api.ExperimentalFaktMultiModule::class)
    collectFakesFrom(projects.core.analytics)
}

Configuration Properties

FlagDefaultExample
enabled true
fakt {
    enabled.set(false)
}
logLevel INFO
fakt {
    logLevel.set(LogLevel.DEBUG)
}
enableCallHistory true
fakt {
    enableCallHistory.set(false)
}
enableMutableFakes false
fakt {
    enableMutableFakes.set(true)
}
useGradleTestFixtures false
fakt {
    useGradleTestFixtures.set(true)
}
collectFrom Not set
fakt {
    @OptIn(ExperimentalFaktMultiModule::class)
    collectFakesFrom(projects.core.analytics)
}

Log Level Details

LevelDescriptionExample
INFO
(default)
Concise summary with key metrics. Use for local development and monitoring cache effectiveness.
fakt {
    logLevel.set(LogLevel.INFO)
}
Output:
Fakt: 101 fakes generated in 35ms (50 cached)
  Interfaces: 101 | Classes: 0
  FIR: 6ms | IR: 29ms
  Cache: 50/101 (49%)
DEBUG Detailed FIR + IR phase timing. Use for troubleshooting, performance analysis, and bug reports.
fakt {
    logLevel.set(LogLevel.DEBUG)
}
Output:
Registering FIR extension
Registering IR extension with FIR metadata access
Built IR class map with 149 classes
FIR→IR Transformation (interfaces: 101/101, took 1ms)
FIR + IR trace
├─ Total FIR time: 6ms
├─ Total IR time: 58ms
│  ├─ FIR analysis: 1 type parameters, 6 members (55µs)
│  └─ IR generation: FakeDataCacheImpl 83 LOC (766µs)
│  ├─ FIR analysis: 2 type parameters, 1 members (23µs)
│  └─ IR generation: FakeMapTransformerImpl 23 LOC (335µs)
QUIET No output except errors. Use for CI/CD pipelines and production builds.
fakt {
    logLevel.set(LogLevel.QUIET)
}
Output: None (silent)

Call History Configuration

Control whether generated fakes include call tracking and verification capabilities.

SettingDescriptionExample
true
(default)
Full call history with: - `methodNameCalls` StateFlow properties - `methodNameCallHistory` lists - `verifyMethodName { }` DSL
fakt {
    enableCallHistory.set(true)
}
false Lightweight fakes with only behavior configuration. No call history overhead.
fakt {
    enableCallHistory.set(false)
}

Per-Interface Override

Individual interfaces can override the project default:

import com.rsicarelli.fakt.CallHistoryMode

// Always generate call history (even if plugin default is false)
@Fake(callHistory = CallHistoryMode.ENABLED)
interface PaymentService { ... }

// Never generate call history (even if plugin default is true)
@Fake(callHistory = CallHistoryMode.DISABLED)
interface Logger { ... }

// Follow plugin default
@Fake  // or @Fake(callHistory = CallHistoryMode.DEFAULT)
interface UserService { ... }

Resolution order: Annotation setting takes precedence over plugin default.


Mutable Fakes Configuration

Control whether generated fakes are mutable (reconfigurable mid-test) or immutable (fixed at construction). For an in-depth exploration of when to use each mode, see Immutable vs Mutable.

SettingDescriptionExample
false
(default)
Immutable fakes with: - `private val` behavior properties - Behavior fixed at construction time - No `modify {}` method
fakt {
    enableMutableFakes.set(false)
}
true Mutable fakes with: - `@Volatile private var` behavior properties - `modify {}` method for selective reconfiguration - Mid-test behavior changes
fakt {
    enableMutableFakes.set(true)
}

Per-Interface Override

Individual interfaces can override the project default:

import com.rsicarelli.fakt.MutabilityMode

// Always generate mutable fake (even if plugin default is false)
@Fake(mutability = MutabilityMode.MUTABLE)
interface UserRepository { ... }

// Always generate immutable fake (even if plugin default is true)
@Fake(mutability = MutabilityMode.IMMUTABLE)
interface Logger { ... }

// Follow plugin default
@Fake  // or @Fake(mutability = MutabilityMode.DEFAULT)
interface UserService { ... }

Resolution order: Annotation setting takes precedence over plugin default.


Multi-Module Configuration

ModeExample
Type-safe accessor
fakt {
    @OptIn(ExperimentalFaktMultiModule::class)
    collectFakesFrom(projects.core.analytics)
}
String-based path
fakt {
    @OptIn(ExperimentalFaktMultiModule::class)
    collectFakesFrom(project(":core:analytics"))
}

For complete multi-module documentation, see Multi-Module Guide.


IDE Integration

IntelliJ IDEA / Android Studio

Generated fakes appear in build/generated/fakt/ and are automatically indexed.

Enable K2 Mode for better autocomplete:

  1. SettingsLanguages & FrameworksKotlin
  2. Enable K2 mode
  3. Restart IDE

K2 mode improves factory function autocomplete and type inference.

Generated Sources Location

Source Set Generated Output
commonTest/ build/generated/fakt/commonTest/kotlin/
jvmTest/ build/generated/fakt/jvmTest/kotlin/
iosTest/ build/generated/fakt/iosTest/kotlin/
androidUnitTest/ build/generated/fakt/androidUnitTest/kotlin/
testFixtures/ build/generated/fakt/testFixtures/kotlin/ (requires useGradleTestFixtures)

Next Steps