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

[#250 clone] Run `ktlint` in process isolation + allow overriding `ktlint` version

Open mateuszkwiecinski opened this issue 3 years ago • 4 comments

Clone of #250 with my suggested improvements/changes

  1. new configurations will be automatically configured, even for custom tasks
  2. It's possible to override ktlint version
  3. @hrach's custom rules were migrated to new ktlint 0.47.1 apis
  4. I slightly changed the way errors are reported back
  5. Plugin itself won't expose ktlint dependency anymore to its consumer (it's defined as compileOnly now)
  6. default runtime ktlint version is kept in sync with the one compilation uses
  7. [new] It doesn't only uses ktlint APIs, but also resolves rules from the ktlint version provided via plugin extension

Fixes #280 Fixes #34

mateuszkwiecinski avatar Sep 10 '22 21:09 mateuszkwiecinski

Potential blocker: https://github.com/gradle/gradle/issues/21964

mateuszkwiecinski avatar Sep 14 '22 08:09 mateuszkwiecinski

Hey @mateuszkwiecinski! Looking forward to this PR! I'm wondering if you have considered just manually loading the custom rules using something like:

fun ktlintRulesetsFromClasspath(classpath: ConfigurableFileCollection): List<RuleSetProviderV2> {
    // Load the files from the classpath into a new ClassLoader
    @Suppress("DEPRECATION")
    val fileUris = classpath.map { it.toURL() }.toTypedArray()
    val classLoader = URLClassLoader(fileUris, Thread.currentThread().contextClassLoader)
    return ServiceLoader.load(RuleSetProviderV2::class.java, classLoader).toList()
}

Where classpath here is the ktlintClasspath. That way we can bypass the processIsolation issues, at least temporarily.

Karn avatar Sep 30 '22 19:09 Karn

@Karn Thanks for sharing the idea💡 I haven't considered any workarounds yet, mainly because the process isolation works just fine. I did some manual testing, and it all worked like a charm. The blocker I stumbled upon turned out not being related to the process isolation, but rather the quirky behavior of Gradle TestKit testing framework 🤷 I disabled problematic tests on Windows, and the PR should soon reach reviewable state :)

mateuszkwiecinski avatar Oct 01 '22 11:10 mateuszkwiecinski

Friendly reminder - it would be great to have the functionality for custom rules. Thank you.

hrach avatar Dec 05 '22 14:12 hrach