kotlinter-gradle
kotlinter-gradle copied to clipboard
[#250 clone] Run `ktlint` in process isolation + allow overriding `ktlint` version
Clone of #250 with my suggested improvements/changes
- new configurations will be automatically configured, even for custom tasks
- It's possible to override
ktlintversion - @hrach's custom rules were migrated to new ktlint 0.47.1 apis
- I slightly changed the way errors are reported back
- Plugin itself won't expose
ktlintdependency anymore to its consumer (it's defined ascompileOnlynow) - default runtime ktlint version is kept in sync with the one compilation uses
- [new] It doesn't only uses
ktlintAPIs, but also resolves rules from thektlintversion provided via plugin extension
Fixes #280 Fixes #34
Potential blocker: https://github.com/gradle/gradle/issues/21964
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 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 :)
Friendly reminder - it would be great to have the functionality for custom rules. Thank you.