This message was deleted.
# kotlin-dsl
s
This message was deleted.
j
spotless allows passing any file, even in different projects, so you can just apply spotless on buildSrc and add the build file itself
t
@Ben Stav you are looking for https://github.com/pinterest/ktlint the one also does formatting for
build.gradle.kts
files.
b
@Javi That's interesting, are you referring to passing any file while configuring spotless, or on the command line when running
spotlessCheck
or
spotlessApply
? If the latter, I'm not sure how to go about doing that, since I don't think they accept any flags or configuration, like
./gradlew spotlessCheck path/to/file
would try to run the last one as a task
@Tom Koptel oohh, yes I've seen that, I just haven't seen a way to tell gradle to sort of...run that on itself. Since the gradle files aren't part of the "real" Java codebase, from my understanding gradle is "blind" to them, they're not caught under any convention
In other words if spotless is configured as part of the Java convention, I don't know as part of what convention (or otherwise!) to add ktlint
t
I am using ktlint directly in the project. Applying plugin to the module will add a task
:module:ktlintKotlinScriptFormat
The one will do the formatting of the
.gradle.kts
script file for you.
👀 1
j
When configuring spotless block
party gradlephant 1
I don’t know about the combination of ktlint + spotless, I prefer ktfmt over ktlint which is supported by spotless too
b
@Javi That was actually surprisingly simpler than I expected
Copy code
spotless {
  kotlin {
    ktfmt()
    target("**/*.gradle.kts")
  }
}
That also catches the bazillion subprojects, so no need to scratch my head on how to apply that plugin for all the subprojects, which is good Thanks! It really was a case of just doing it
j
yeah, indeed you can apply it in the root project only and pick all kt and kts files in all folders, so all files are processed, but it would be better to do it per project in order to parallelize the tasks execution
and remember to exclude build directories to avoid formatting unnecessary code
b
You're very correct, I was very confused before throwing in a:
Copy code
targetExclude("**/build/")
j
ktlint-gradle will automatically include your build scripts in the linting. they lint under a different task as well to provide some separation between your source and buildscripts