question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Cannot exclude generated code

See original GitHub issue

We are using the jooq gradle plugin to generate some kotlin code (https://github.com/etiennestuder/gradle-jooq-plugin) Obviously I would like to exclude this code from ktlint. Code gets generated in <project>/build/generated-src It seems this is impossible. Here is the attempt I made:

ktlint {
    version = libs.versions.ktlint.get()
    debug = true
    verbose = true
    filter {
        include { element ->
            println(element.file.path)
            println(!element.file.path.contains("generated-src"))
            !element.file.path.contains("generated-src")
        }
        exclude { element ->
            println(element.file.path)
            println(element.file.path.contains("generated-src"))
            element.file.path.contains("generated-src")
        }
    }
}

With the above kode ktlint still fails on the generated code.

Issue Analytics

  • State:closed
  • Created 2 years ago
  • Reactions:2
  • Comments:6 (1 by maintainers)

github_iconTop GitHub Comments

3reactions
NikolayMetchevcommented, Nov 3, 2021

Here is how I got it to work:

ktlint {
    filter {
        exclude { entry ->
            entry.file.toString().contains("generated")
        }
    }
}
1reaction
dlurtoncommented, Aug 13, 2021

I have a similar setup with a generated-src directory and for the life of me I could not make the plugin exclude that directory.

However, I found that if I: rm -rf .gradle and then ./gradlew ktlintCheck the exclusions worked just fine. This suggests to me that the plugin is simply re-running ktlint on the same files it failed on previously without re-applying the exclude filter.

Seems like a legit bug.

Read more comments on GitHub >

github_iconTop Results From Across the Web

To exclude the generated code from sonar analysis on Quality ...
I have been trying several option but in vain please help. <properties> <sonar.exclusions>**/generatedsources/fod1/fod2/**/*.java</sonar ...
Read more >
ReSharper - Configure code inspection settings - JetBrains
Exclude specific files and folders from code inspection · Select ReSharper | Options from the main menu or press Alt+R O , then...
Read more >
Configure code analysis rules - .NET - Microsoft Learn
Exclude generated code .NET code analyzer warnings aren't useful on generated code files, such as designer-generated files, which users can't ...
Read more >
Exclusions from Jacoco Report - Baeldung
Generally, the candidates for exclusion can be configuration classes, POJOs, DTOs, as well as generated byte code.
Read more >
Exclude java warnings in generated code - Genuitec
This code is generated in its own package, so I tried to exclude that from validation. The warnings don't go away. It seems...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found