https://kotlinlang.org logo
#gradle
Title
# gradle
e

Edoardo Luppi

09/28/2023, 12:59 PM
I'd like to integrate KtLint into Gradle. Do you recommend kotlinter-gradle or ktlint-gradle? How's your experience with them?
w

wakingrufus

09/28/2023, 1:54 PM
i recommend ktlint-gradle, but I am biased, since I am one of the developers lol. the main benefit ktlint-gradle provides is that it is decoupled from the ktlint version. so you can configure ktlint-gradle to use any* version of the ktlint tool. *within the supported version range for that version of ktlint-grade
e

Eugen Martynov

09/28/2023, 1:55 PM
We run ktlint as part of detekt
e

Edoardo Luppi

09/28/2023, 1:56 PM
Thanks @wakingrufus, biased answers are ok! @Eugen Martynov interesting! So Detekt adds ktlint issues as part of its own report?
w

wakingrufus

09/28/2023, 1:57 PM
dtekt has a feature to run ktlint as an extension of detekt
👆 1
e

Eugen Martynov

09/28/2023, 1:57 PM
It can also format your code
w

wakingrufus

09/28/2023, 1:58 PM
why does controlling the ktlint version matter, you ask? because ktlint sometimes drastically changes behavior between versions, it can be helpful to be able to control that version and upgrade on your own timeline while staying on the latest version of the gradle plugin
e

Edoardo Luppi

09/28/2023, 1:58 PM
I did watch @gammax talk some time ago about Detekt and was really interested in using it for custom rules. Do you recommend starting with it straight away?
w

wakingrufus

09/28/2023, 1:59 PM
i use detekt along side ktlint-gradle
and opt not to use the ktlint part of detekt
but detekt is really nice for its main function
e

Edoardo Luppi

09/28/2023, 1:59 PM
and opt not to use the ktlint part of detekt
Any reason for that or just to keep it "clean"?
w

wakingrufus

09/28/2023, 2:00 PM
and i dont know how it works, but intellij can autocomplete the detekt.yml
the reason is because the ktlint-gradle plugin behaves how you would expect a tool plugin to work: setting tool version as explained above, using the worker api to break down work on a per file basis, etc. since detekt runs it as an extension of detekt, its not really like a first class gradle plugin
e

Eugen Martynov

09/28/2023, 2:05 PM
In addition what John said - I can not find easily what ktlint version is used by detekt. Ktlint looks like got a major update recently with some breaking changes.
w

wakingrufus

09/28/2023, 2:09 PM
yeah ktlint did a lot of breaking changes recently in the lead up to 1.0. being able to support all of these versions of ktlint in the same version of the ktlint-gradle plugin was a lot of work, but I thought it was important because that is how things like pmd, checkstyle, etc work, so it should be true of the ktlint plugin as well
and detekt and kotlinter have not done this (each version of the plugin is locked to a specific version of ktlint), so that is the main differentiator imo
e

Eugen Martynov

09/28/2023, 2:31 PM
Correct, thanks for this question I also created ticket for the detekt https://github.com/detekt/detekt/issues/6515
2 Views