Skip to main content

Setup

  1. Apply Gradle plugin:
plugins {
kotlin("multiplatform") version "2.0.0" // ...or any other Kotlin plugin
id("dev.mokkery") version "2.1.1"
}
  1. Ensure that your Mokkery version is compatible with your Kotlin version. Refer to the compatibility section.

  2. Check the source sets section to make sure that Mokkery is properly applied in your project.

  3. Check the targets section to make sure that all targets from you multiplatform project are supported.

  4. At this point everything should be fine. In case of Gradle being unable to find dependencies, check missing repositories.

// for runtime dependencies
repositories {
mavenCentral()
}
// for plugin dependencies
pluginManagement {
repositories {
gradlePluginPortal()
mavenCentral()
}
}

Convention plugins

For those using convention plugins, make sure that the dependencies configuration includes the path to the required Maven repository, which can be added using gradlePluginPortal().

dependencyResolutionManagement {
repositories {
mavenCentral()
// required to download gradle plugin
gradlePluginPortal()
}
}

Once the required Maven repository is connected, you will be able to successfully download the Mokkery plugin dependency.

dependencies {
implementation("dev.mokkery:mokkery-gradle:2.1.1")
}

Source sets

By default, Mokkery is applied to all Kotlin source sets in the project that either contain the word 'Test' in their names or are named exactly 'test'. As a result, Mokkery is correctly applied to the default test source sets in Android, JVM, or Multiplatform projects. However, this default behavior might need adjustments if any of your main custom source sets contain the word 'Test'.

warning

Before version 2.1.0, Mokkery was applied by default only to source sets whose names contained the phrase 'Test'. In result it was not applied in JVM projects.

To change the default behavior, you can provide a different rule in your Gradle file:

import dev.mokkery.gradle.ApplicationRule.Listed
import dev.mokkery.gradle.ApplicationRule.MatchesName

plugins {
kotlin("multiplatform")
id("dev.mokkery")
}

mokkery {
rule.set(Listed("jvmTest")) // Mokkery is applied to jvmTest source set
rule.set(MatchesName(Regex("macos.*Test"))) // Mokkery is applied to source sets matching "macos.*Test"
rule.set { it.name.endsWith("Test") } // Mokkery is applied to source sets ending with "Test"
}

Targets

✅ Supported:

You can refer to this file for more details.

Compatibility

warning

Mokkery 2.* versions aren't tied to specific Kotlin 2.* versions, assuming the compiler API will stay stable. However, breaking changes can cause compile-time errors that require updating Mokkery. Track compiler API stability here.

Mokkery versionSupported Kotlin versions
2.0.0 – 2.1.12.0.0+