Spent a few hours fighting the <ktfmt gradle plugi...
# ktfmt
c
Spent a few hours fighting the ktfmt gradle plugin, hitting these issues: • plugin changes language version from 1.9.0 (Kotlin 1.8.22 w/ lang ver 1.9 to get data objects) to something else (IntelliJ no longer recognized data objects); • ClassNotFoundError on incremental compilation Seems like design issues, slapping ktfmt & its Kotlin deps on build classpath alongside frequently-incompatible Kotlin versions and praying it all works out. Plugin should likely use worker classpath isolation or other approaches to separate what ktfmt needs from what the build needs. Which is the workaround I’m into now, run ktfmt via CLI or JavaExec.
g
Hey 👋 author of the plugin here. Don't you mind opening an issue for this?
K 1
👍 1
If anyone is looking for a workaround to using the plugin, this Gradle snippet lets you run ktfmt, without exclusions, incremental processing, etc.
Copy code
val ktfmt by configurations.creating

dependencies { ktfmt("com.facebook:ktfmt:0.44") }

val ktfmtFormat by
    tasks.registering(JavaExec::class) {
        val ktfmtArgs =
            mutableListOf("--kotlinlang-style", layout.projectDirectory.asFile.absolutePath)
        if (System.getenv()["CI"] != null) ktfmtArgs.add("--set-exit-if-changed")
        group = "formatting"
        description = "Run ktfmt"
        classpath = ktfmt
        mainClass.set("com.facebook.ktfmt.cli.Main")
        //        jvmArgs("--add-opens=java.base/java.lang=ALL-UNNAMED")
        args(ktfmtArgs)
    }

val check = tasks.named("check") { dependsOn(ktfmtFormat) }

tasks.register("precommit") { dependsOn(check) }
👍 1