Skip to content

Sometimes CI throws an exception when running ktlintFormat on empty modules #3280

@nuhkoca

Description

@nuhkoca

Expected Behavior

When running ktlintFormat (or any ktlint task) on a module that contains no .kt or .kts source files, ktlint should gracefully skip the module with no errors. Empty modules (e.g., newly scaffolded feature modules with only a build.gradle.kts) are common in large modular Android projects and should not cause build failures.

Observed Behavior

Running ktlintFormat on an empty module (no Kotlin source files) causes the loadKtlintReporters task to fail with a NoClassDefFoundError:

* What went wrong:
Execution failed for task ':features:myModule:loadKtlintReporters'.
> A failure occurred while executing org.jlleitschuh.gradle.ktlint.worker.LoadReportersWorkAction
   > com/pinterest/ktlint/cli/reporter/core/api/ReporterProviderV2

This failure is intermittent — it does not happen on every run, but it regularly breaks CI builds.

Steps to Reproduce

  1. Create a multi-module Android/Kotlin project with the org.jlleitschuh.gradle.ktlint plugin applied via a convention plugin to all modules.
  2. Add an empty module (e.g., features/my-module/) that has a build.gradle.kts but contains no .kt or .kts source files.
  3. Run ./gradlew ktlintFormat (or ktlintCheck).
  4. Observe that loadKtlintReporters fails on the empty module. The failure is intermittent and more easily reproduced in CI environments.

Your Environment

  • Version of ktlint used: 1.7.1
  • Relevant parts of the .editorconfig settings:
    [*.{kt,kts}]
    max_line_length=120
    indent_size=4
    ktlint_code_style=android_studio
    ij_kotlin_allow_trailing_comma=true
    ij_kotlin_allow_trailing_comma_on_call_site=true
  • Name and version of integration used: org.jlleitschuh.gradle:ktlint-gradle:14.0.1 (applied via Gradle convention plugin)
  • Version of Gradle used: 9.2.1
  • Operating System and version: macOS (CI also runs on Linux)

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions