kotlinter-gradle icon indicating copy to clipboard operation
kotlinter-gradle copied to clipboard

Is that possible to include custom rule from current project?

Open MyDogTom opened this issue 7 years ago • 6 comments

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.

MyDogTom avatar Jan 12 '18 14:01 MyDogTom

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.

jeremymailen avatar Jan 13 '18 06:01 jeremymailen

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.

jeremymailen avatar Jan 19 '18 17:01 jeremymailen

+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"))
}

Kritarie avatar May 19 '22 15:05 Kritarie

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 avatar May 20 '22 06:05 jeremymailen

@jeremymailen pinging this thread... do you think this can be fixed any time soon?

eric239 avatar Aug 30 '22 21:08 eric239

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.

jeremymailen avatar Sep 06 '22 06:09 jeremymailen