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.

Kotlinter is not ignoring generated files

See original GitHub issue

I have several generated kotlin files in my app (inside a build directory) which creates kotlin code that ktlint doesnt like. Since I have no control over the code generation and it is not being checked into git I would like ktlint to ignore the files within the build directory.

I tried adding several variations of exclude("build/**") but each time ktlint was failing on the generated files. Is there any way to ignore the build directory?

Note: I added the exclude directory to "lintKotlinMain"(org.jmailen.gradle.kotlinter.tasks.LintTask::class) { as stated in the README

Thanks so much!

Issue Analytics

  • State:closed
  • Created 2 years ago
  • Comments:28 (14 by maintainers)

github_iconTop GitHub Comments

1reaction
jeremymailencommented, Jul 22, 2021

Yes, will add it as an enhancement request. The Gradle Quality plugin has a similar extra param excludeSources http://xvik.github.io/gradle-quality-plugin/4.6.0/guide/exclusion/

0reactions
ghostcommented, May 23, 2022

Just catching up on this. Thanks @jeremymailen ! I got the exclude working now.

+1 to the enhancement discussed above, it would have been a more intuitive solution to discover and is better “documentation” that it is generated code being ignored.

Could you explain how you make it work? Im facing the same issue, Im using a code generator plugin for my Graphql API (DGS codegen from netflix) and everything in goes into the /build/generated path outside the main project, and I cant make it work to ignore it, with ktlint gradle it works like a charm doing this:

ktlint {
    filter {
        exclude { element ->
            element.file.path.contains("generated/")
        }
    }
}

But with this plugin it doesnt work at all

We need a standard way to fix this problem…This issue must be open.

EDIT: Found a solution

tasks.formatKotlinMain {
    exclude { it.file.path.contains("generated/")}
}

tasks.lintKotlinMain {
    exclude { it.file.path.contains("generated/")}
}
Read more comments on GitHub >

github_iconTop Results From Across the Web

Kotlin exclude ktlint directories in maven - Stack Overflow
I found the solution here https://github.com/gantsign/ktlint-maven-plugin/issues/341. And we just have to use below to avoid target files.
Read more >
Exclude Kotlin files from gradle build - Help/Discuss
I want to exclude Kotlin files from a gradle build. ... fine but after converting them to Kotlin the files seem not to...
Read more >
Step by Step: How to setup ktlint with spotless? - SourceLevel
Learn how to set up ktlint using spotless. Amadeu Cavalcante shows step by step how to configure ktlint using Gradle and spotless.
Read more >
Static Analysis Tools - ktlint - The Android Arsenal
This rule does not apply in a number of situations. ... Check all '.kt' files in 'src/' directory, but ignore files ending with...
Read more >
Ktlint
Some rules do allow further configuration, but in all cases a reasonable default is set when not provided. ktlint primarily uses the .editorconfig...
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