Hey folks, I'm trying to set git hooks with kotlin...
# ktlint
a
Hey folks, I'm trying to set git hooks with kotlinter. The docs say Gradle tasks to install pre-commit, pre-push hooks are provided, but the code snippets do not seem to work (neither Kotlin nor Groovy versions) Please help me understand the right way to install kotlinter Git hooks. Thank you in advance:)
plus one 1
s
@Jeremy Mailen would you be able to help out?
i'm not familiar with the kotlinter plugin; can you elaborate about what about it is not working?
a
Yes, sure. Actually, I figured it out. The issue was that docs say that inserting this snippet at the end of my build.gradle file (Groovy) should automatically install the pre-push hook on every build.
Copy code
tasks.named('check') {
    dependsOn 'installKotlinterPrePushHook'
}
However, neither the 'check' task is found, nor the 'installKotlinterPrePushHook'. What worked instead for me was this:
Copy code
tasks.getByPath(':app:preBuild').dependsOn(installPreCommitHook, installKotlinterPrePushHook)
Note: installPreCommitHook is a custom Gradle Task that I made following some blog. Now that I know how it works, I'm very happy and will likely prefer kotlinter over other ktlint plugins due to such seamless hook installation. Thanks @Jeremy Mailen for creating an awesome tool!
s
glad you figured it out. thanks for putting your solution here so that it can help others