https://kotlinlang.org logo
#ktlint
Title
d

Dariusz Kuc

03/02/2020, 10:19 PM
hello! I'm writing a custom Gradle plugin that generates source files and was wondering if there is a way I could automatically exclude them from ktlint check?, e.g. I'm using
org.jlleitschuh.gradle.ktlint
which automatically applies the linter against all source sets. Currently I'm manually configuring
ktlint
task to filter out
generated
sources but was wondering whether there is some better way?
Copy code
tasks {
    ktlint {
        filter {
            exclude("**/generated/**")
        }
    }
}
e.g. above approach is not ideal as anyone using the plugin will have to add that configuration as well
t

tapchicoma

03/02/2020, 10:25 PM
you could configure this via your plugin
something like
extensions.configure(KtlintExtension::class.java) { filter { exclude(..) }}
d

Dariusz Kuc

03/02/2020, 10:26 PM
guess would have to conditionally check if ktlint is applied
but yeah probably should do that
t

tapchicoma

03/02/2020, 10:28 PM
you could wrap it in
plugins.withId("org.jlleitschuh.gradle.ktlint") { // configure extension here }
d

Dariusz Kuc

03/03/2020, 12:35 AM
Hmm in order to configure the extension I'd have to add it to plugin dependencies. Unsure if I want to do it
m

mbonnin

03/03/2020, 8:05 AM
You could certainly make it a compileOnly dependency ?
1
7 Views