Skip to content

Kotlin Projects

For Kotlin projects, the IntelliJ coverage engine provides better accuracy than JaCoCo, especially for inline functions, coroutines, and suspend functions.

Why IntelliJ Coverage for Kotlin?

JaCoCo instruments bytecode, which can miss or misreport coverage for Kotlin-specific features:

Feature JaCoCo IntelliJ
Inline functions Often incorrect Accurate
Suspend functions Partial Accurate
Coroutines Partial Accurate
Default parameters Sometimes incorrect Accurate
Companion objects Accurate Accurate

Configuration

Switch to IntelliJ coverage engine:

configure<io.github.surpsg.deltacoverage.gradle.DeltaCoverageConfiguration> {
    coverage {
        engine = CoverageEngine.INTELLIJ
    }

    diffSource.git.compareWith("refs/remotes/origin/main")
}

The plugin automatically applies the CoverJet plugin which uses IntelliJ coverage under the hood.

CoverJet Plugin

CoverJet is a Gradle plugin that integrates IntelliJ coverage into Gradle builds. When you set engine = CoverageEngine.INTELLIJ, Delta Coverage:

  1. Applies CoverJet plugin to all projects
  2. Configures test tasks to collect IntelliJ coverage
  3. Reads .ic coverage files instead of .exec

Manual CoverJet Setup

If you need custom CoverJet configuration:

// build.gradle.kts
plugins {
    id("io.github.gw-kit.cover-jet") version "1.0.0"
}

configure<io.github.surpsg.deltacoverage.gradle.DeltaCoverageConfiguration> {
    coverage {
        engine = CoverageEngine.INTELLIJ
        autoApplyPlugin = false  // Don't auto-apply, we did it manually
    }
}

Mixed Java/Kotlin Projects

IntelliJ coverage works well for mixed projects. It provides accurate coverage for both Java and Kotlin code.

coverage {
    engine = CoverageEngine.INTELLIJ  // Works for Java too
}

Excluding Kotlin-Generated Code

Exclude Kotlin metadata and synthetic classes:

excludeClasses.value(
    listOf(
        "**/*\$DefaultImpls.class",
        "**/*\$Companion.class",
        "**/*\$WhenMappings.class"
    )
)

Troubleshooting

Coverage shows 0% for inline functions

Switch to IntelliJ engine:

coverage {
    engine = CoverageEngine.INTELLIJ
}

"Cannot find CoverJet plugin"

Ensure you have access to the plugin. Add to your settings.gradle.kts:

pluginManagement {
    repositories {
        gradlePluginPortal()
        mavenCentral()
    }
}

Coverage binary files not found

Verify test tasks ran and produced .ic files:

find build -name "*.ic"

Use the explain report to debug:

./gradlew deltaCoverage -PexplainOnly