Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Ktlint checks generated source since 12.1.0 #746

Open
ede-wolf-gls opened this issue Jan 22, 2024 · 6 comments
Open

Ktlint checks generated source since 12.1.0 #746

ede-wolf-gls opened this issue Jan 22, 2024 · 6 comments

Comments

@ede-wolf-gls
Copy link

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
Copy link

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
Copy link

dhladik commented Jan 24, 2024

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
Copy link

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 pachli/pachli-android#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
Copy link

aanno commented Feb 1, 2024

Hhm,

for me

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

did not work, but

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

did!

@rmcmk
Copy link

rmcmk commented Feb 9, 2024

Same problem here.

@edpichler
Copy link

edpichler commented Feb 24, 2024

Here is a workaround: #751

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

6 participants