kotlinter-gradle
kotlinter-gradle copied to clipboard
Is that possible to include custom rule from current project?
Readme states two ways how to add custom rules
buildscript {
dependencies {
classpath files('libs/my-custom-ktlint-rules.jar')
classpath 'org.other.ktlint:custom-rules:1.0'
}
}
I'd like to have custom rules as separate module in my project. Is that possible to include them directly? Ideally, I'd like that these rules are applied against themselves as well.
kotlinter will resolve any lint rules in the classpath of the gradle buildscript. However usually you can only use dependencies in buildscript which can be resolved during gradle's evaluation phase which would exclude anything that gradle build produces. Someone had a similar question here: https://discuss.gradle.org/t/code-generation-problems-buildsrc-and-buildscript-dependency-on-another-module/5681
Chicken and egg problem. You'd probably need a separate gradle build which publishes to mavenLocal or something. It could validate itself against an older published version of itself.
Since I don't think there's anything straightforward we could do in kotlinter to work around this constraint in gradle, I'll close this for now. Thanks.
+1 We currently have a clunky process where we build our custom rules jar, copy it over to a /libs dir (checked into source control), then use buildscript { classpath(...) } to include them. Would rather do what we do for lint rules:
dependencies {
lintChecks(project(":custom-checks"))
}
Let me reopen. There's a PR out proposing this. I think it will need some careful testing, but I might have become paranoid about gradle workers :).
@jeremymailen pinging this thread... do you think this can be fixed any time soon?
It might take a little bit, since the upgrade to ktlint 0.47.x is up next. This would be a bigger change and require careful consideration.