Per https://github.com/gradle/gradle/issues/6790, the Kotlin DSL for gradle is now mature, and we should make sure our docs are clear for both Kotlin and Groovy DSL users. I'm not a Kotlin DSL user yet, and migrating won't make the top of my TODO anytime soon. If any Kotlin DSL users can comment on what parts of our docs are different for Kotlin, that would be great.
Surprisingly, the documentation is pretty solid. And because spotless is strongly typed, it's really solidly self documenting. It's really awesome how having the plugin written in Java has just allowed this to fall out for free.
When doing the translation, basically you just have to add a bunch of parentheses that aren't required in Groovy.
As an example, here's a simple translation:
spotless {
format 'misc', {
target '**/*.gradle', '**/*.md', '**/.gitignore'
trimTrailingWhitespace()
indentWithTabs() // or spaces. Takes an integer argument if you don't like 4
endWithNewline()
}
format 'cpp', {
target '**/*.hpp', '**/*.cpp'
replace 'Not enough space after if', 'if(', 'if ('
replaceRegex 'Too much space after if', 'if +\\(', 'if ('
// Everything before the first #include or #pragma will
// be replaced with whatever is in `spotless.license.cpp`
licenseHeaderFile 'spotless.license.cpp', '#'
}
}
This becomes this in Kotlin:
spotless {
format ("misc") {
target("**/*.gradle", "**/*.md", "**/.gitignore")
trimTrailingWhitespace()
indentWithTabs() // or spaces. Takes an integer argument if you don't like 4
endWithNewline()
}
format ("cpp") {
target("**/*.hpp", "**/*.cpp")
replace("Not enough space after if", "if(", "if (")
replaceRegex("Too much space after if", "if +\\(", "if (")
// Everything before the first #include or #pragma will
// be replaced with whatever is in `spotless.license.cpp`
licenseHeaderFile("spotless.license.cpp", "#")
}
}
I very much agree with @JLLeitschuh's observation! I'm using Spotless in https://github.com/jbduncan/jupiter-collection-testers, which uses the Kotlin DSL, and the only thing I had to do was to make sure I used parentheses. :)
As kotlin users, are the parentheses which are missing from the documentation obvious? If so, then i think we can close this as "already good enough". If not then maybe one of you can take a pass at the gradle README to make sure all the required parens are there, and then we'll close?
For a new user of the Kotlin DSL I would argue that they aren't obvious. I've been working with the Kotlin DSL for almost two years now so I can automatically do the translation very easily.
Maybe I'm wrong, I want to get someone elses insights on this. I'll ask them to take a look.
Here are a couple additional resources for any contributors:
Thank you for providing a great Gradle plugin! 鈥擳he Gradle Team
I've wanted something like Examplar for a long time, thanks for the link.
I'm happy to reopen, but it looks unlikely that we're going to take further action here.
Most helpful comment
For a new user of the Kotlin DSL I would argue that they aren't obvious. I've been working with the Kotlin DSL for almost two years now so I can automatically do the translation very easily.
Maybe I'm wrong, I want to get someone elses insights on this. I'll ask them to take a look.