JLLeitschuh / ktlint-gradle

A ktlint gradle plugin
MIT License
1.48k stars 163 forks source link

Ktlint checks generated source since 12.1.0 #746

Open ede-wolf-gls opened 10 months ago

ede-wolf-gls commented 10 months ago

Since version 12.1.0 of your ktlint gradle plugin, my android build fails.

> Task :app:generateSomeCode FAILED

FAILURE: Build failed with an exception.

* What went wrong:
A problem was found with the configuration of task ':app:generateSomeCode' (type 'GenerateSomeCodeTask').
  - Gradle detected a problem with the following location: '.../app/build/generated/source/constants'.

    Reason: Task ':app:runKtlintCheckOverMainSourceSet' uses this output of task ':app:generateSomeCode' without declaring an explicit or implicit dependency. This can lead to incorrect results being produced, depending on what order the tasks are executed.

    Possible solutions:
      1. Declare task ':app:generateSomeCode' as an input of ':app:runKtlintCheckOverMainSourceSet'.
      2. Declare an explicit dependency on ':app:generateSomeCode' from ':app:runKtlintCheckOverMainSourceSet' using Task#dependsOn.
      3. Declare an explicit dependency on ':app:generateSomeCode' from ':app:runKtlintCheckOverMainSourceSet' using Task#mustRunAfter.

    For more information, please refer to https://docs.gradle.org/8.5/userguide/validation_problems.html#implicit_dependency in the Gradle documentation.

I tried to exclude the generated sources from ktlint checks, but this didn't work

ktlint {
    filter {
        exclude("**/generated/**")
    }
}

I include the generated sources in the main source set like this:

android {
//...
    sourceSets {
        get("main").kotlin.srcDir("<generated source directory>")
    }
}

Could someone help? Maybe I configure something wrong.

nikclayton commented 10 months ago

Until this is fixed put this in .editorconfig:

# Disable ktlint on generated source code, see
# https://github.com/JLLeitschuh/ktlint-gradle/issues/746
[**/build/generated/source/**]
ktlint = disabled
dhladik commented 10 months ago

Until this is fixed put this in .editorconfig:

# Disable ktlint on generated source code, see
# https://github.com/JLLeitschuh/ktlint-gradle/issues/746
[**/build/generated/source/**]
ktlint = disabled

This did not help unfortunately ☹️

nikclayton commented 10 months ago

Until this is fixed put this in .editorconfig:

# Disable ktlint on generated source code, see
# https://github.com/JLLeitschuh/ktlint-gradle/issues/746
[**/build/generated/source/**]
ktlint = disabled

This did not help unfortunately ☹️

Worked in https://github.com/pachli/pachli-android/pull/376 - look at the CI runs for that PR, you'll see the first one failed because of this issue, and adding this editorconfig fixed it.

aanno commented 10 months ago

Hhm,

for me

[**/build/generated/**]
ktlint = disabled

did not work, but

[build/generated/*/main/**]
ktlint = disabled

did!

rmcmk commented 9 months ago

Same problem here.

edpichler commented 9 months ago

Here is a workaround: https://github.com/JLLeitschuh/ktlint-gradle/issues/751

patrickpilch commented 1 month ago

Potentially the root cause: https://github.com/google/ksp/issues/1261/