kotlinter-gradle: Kotlinter is not ignoring generated files

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!

About this issue

  • Original URL
  • State: closed
  • Created 3 years ago
  • Comments: 28 (14 by maintainers)

Commits related to this issue

Most upvoted comments

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/")}
}

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/