Language Server appears to be out of sync with command line gradle
See original GitHub issueHi Kotlin Language Server developers,
Many thanks for a great project. I have been trying to set it up against emacs, but I must be doing something very silly because I get errors with KLS that I do not see when I manually run gradle. Let me first explain my setup. I am using Debian testing on x64 and I installed kotlin using SDK Man [0]. I have tried two distinct setups though, sadly, with more or less the same outcome.
Setup using Java 11
I have read through the many posts detailing how it is not possible to use Java 11 to build KLS - e.g. [1, 2, 3] - but it was still unclear to me if this limitation also applied to building user projects or only to building KLS itself [4]. So I started first by installing openjdk-11 and using the binaries supplied on GitHub [5]. Though there is no out of the box support on emacs for KLS [6], thanks to the help of the emacs lsp community, I managed to get emacs to start KLS and report errors on my kotlin code.
The weird thing was that it all worked well at first, but as I started to add more dependencies and change the project files, I started to see errors in KLS that I do not see in gradle. In particular, I see:
Server.kt 20 27 error INTER… kotlin: Calls to static methods in Java interfaces are prohibited in JVM target 1.6. Recompile with '-jvm-target 1.8' (lsp-ui)
Server.kt 27 33 error INTER… kotlin: Calls to static methods in Java interfaces are prohibited in JVM target 1.6. Recompile with '-jvm-target 1.8' (lsp-ui)
However, my gradle file states:
tasks.withType<KotlinCompile> {
kotlinOptions.jvmTarget = "1.8"
}
In addition, my kts (gradle Kotlin script files) are riddled with errors:
build.gra… 1 29 error UNRES… kotlin: Unresolved reference: gradle (lsp-ui)
build.gra… 3 1 error UNRES… kotlin: Unresolved reference: plugins (lsp-ui)
build.gra… 4 5 error UNRES… kotlin: Unresolved reference: application (lsp-ui)
build.gra… 5 5 error UNRES… kotlin: Unresolved reference: id (lsp-ui)
...
The first error stems from this line:
import org.jetbrains.kotlin.gradle.tasks.KotlinCompile
To the untrained eye, it seems like the gradle kotlin DSL files are just not being picked up correctly.
Setup using Java 8
I then decided to investigate two questions:
- check if there have been fixes in master that address my problem;
- check if Java 11 is also not supported in user projects.
For this I relied on openjdk-8, but sadly it is not (entirely) available on Debian testing. The missing packages were downloaded manually from their FTP server [7]:
openjdk-8-jdk_8u212-b03-2_deb9u1_amd64.deb
openjdk-8-jdk-headless_8u212-b03-2_deb9u1_amd64.deb
Once installed I selected the java version via alternatives:
update-alternatives --config java
And set it to Java 8. I confirmed that my binaries were running from Java 8, as well as my local build using gradle. I then git cloned KLS and built it as per my understanding of the instructions:
./gradlew server:build
./gradlew server:installDist
It all worked fine. I then installed the resulting binaries, restarted emacs and picked up the new KLS. However, I am getting exactly the same errors as I had before, as per section above.
Conclusions
So it seems to me my problems are actually not related to the java version, but to my project. The weird thing is that when I run gradle build
(or via the gradle wrapper) it all works. So I’m trying to figure out what KLS is doing differently. Can you point out to mistakes I have done on my setup, or if nothing obvious can be spotted, on ways to get more debug information about what KLS is doing?
Thanks very much for all your help.
Marco
[0] https://kotlinlang.org/docs/tutorials/command-line.html [1] https://github.com/fwcd/KotlinLanguageServer/issues/125 [2] https://github.com/fwcd/KotlinLanguageServer/issues/108 [3] https://github.com/fwcd/KotlinLanguageServer/issues/114 [4] https://github.com/fwcd/KotlinLanguageServer/pull/124 [5] https://github.com/fwcd/KotlinLanguageServer/releases/tag/0.1.13 [6] https://github.com/emacs-lsp/lsp-mode/issues/900 [7] http://ftp.debian.org/debian/pool/main/o/openjdk-8/
Issue Analytics
- State:
- Created 4 years ago
- Comments:8 (1 by maintainers)
Thanks for investigating and providing such a detailed description of the issue!
I have to admit that I haven’t got around to test the compiled KLS on Java 11 projects yet, though this will definitely be part of #109, since KLS should always support its own codebase.
A ticket for this already exists [1], so I’ll move the discussion there.
[1] https://github.com/fwcd/KotlinLanguageServer/issues/72