Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[Deps] Investigate ways of integrating ktfmt #338

Open
rami3l opened this issue Mar 20, 2022 · 1 comment
Open

[Deps] Investigate ways of integrating ktfmt #338

rami3l opened this issue Mar 20, 2022 · 1 comment
Labels
formatting Related to source code formatting

Comments

@rami3l
Copy link

rami3l commented Mar 20, 2022

We're vendoring ktfmt (here) since it uses the embedded Kotlin compiler rather than the standard one, which we use. The embedded Kotlin compiler uses other package paths (e.g. org.jetbrains.kotlin.com.intellij instead of com.intellij), which causes weird clashes at runtime, for example:

java.lang.NoSuchMethodError: 'org.jetbrains.kotlin.cli.jvm.compiler.KotlinCoreEnvironment org.jetbrains.kotlin.cli.jvm.compiler.KotlinCoreEnvironment$Companion.createForProduction(org.jetbrains.kotlin.com.intellij.openapi.Disposable, org.jetbrains.kotlin.config.CompilerConfiguration, org.jetbrains.kotlin.cli.jvm.compiler.EnvironmentConfigFiles)'
            at com.facebook.ktfmt.format.Parser.parse(Parser.kt:45)
            at com.facebook.ktfmt.format.Formatter.sortedAndDistinctImports(Formatter.kt:141)
            at com.facebook.ktfmt.format.Formatter.format(Formatter.kt:84)
            at org.javacs.kt.formatting.FormatterKt.formatKotlinCode(Formatter.kt:10)
            at org.javacs.kt.KotlinTextDocumentService$formatting$1.invoke(KotlinTextDocumentService.kt:204)
            at org.javacs.kt.KotlinTextDocumentService$formatting$1.invoke(KotlinTextDocumentService.kt:199)
            at org.javacs.kt.util.AsyncExecutor.compute$lambda-2(AsyncExecutor.kt:19)
            at java.base/java.util.concurrent.CompletableFuture$AsyncSupply.run(CompletableFuture.java:1700)
            at java.base/java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1128)
            at java.base/java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:628)
            at java.base/java.lang.Thread.run(Thread.java:829)

While this is non-ideal, it's currently the best solution I could find that works for our setup. A better solution would be to automate this as part of our Gradle build (i.e. rewrite the package paths and replace the transitive kotlin-compiler-embeddable dependency with kotlin-compiler - basically do this automatically), but I couldn't figure out a clean way of doing so yet.

Originally posted by @fwcd in #330 (comment)


... there were other dependencies which needed the non-embedded compiler and didn't have an embedded version themselves (I think it was the kotlin-scripting-compiler or perhaps the IDEA plugin, which we no longer depend on though, can't remember).

Originally posted by @fwcd in #330 (comment)

@fwcd fwcd added the formatting Related to source code formatting label Mar 21, 2022
@casret
Copy link

casret commented Feb 6, 2024

@fwcd can we update the vendored version, it's a couple years out of data at this point?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
formatting Related to source code formatting
Projects
None yet
Development

No branches or pull requests

3 participants