question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Language Server appears to be out of sync with command line gradle

See original GitHub issue

Hi 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:closed
  • Created 4 years ago
  • Comments:8 (1 by maintainers)

github_iconTop GitHub Comments

1reaction
fwcdcommented, Jul 17, 2019

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.

0reactions
mcraveirocommented, Jul 17, 2019

A ticket for this already exists [1], so I’ll move the discussion there.

[1] https://github.com/fwcd/KotlinLanguageServer/issues/72

Read more comments on GitHub >

github_iconTop Results From Across the Web

It is currently in use by another Gradle instance - Stack Overflow
I'm running/building it in command line. I am referring User guide. And, doing some simple tasks. When I start to run simple tasks,...
Read more >
Command-Line Interface - Gradle User Manual
Run gradle --status to list running and recently stopped Gradle daemons. Only displays daemons of the same Gradle version. --stop (Standalone command). Run ......
Read more >
Language Server Extension Guide - Visual Studio Code
To run the Language Server, do the following steps: Press Ctrl+Shift+B to start the build task. The task compiles both the client and...
Read more >
Running Gradle from Visual Studio Code - Syncfusion
Learn about loading a gradle project into vs code in the chapter "Running Gradle from Visual Studio Code" of Syncfusion Gradle free ebook....
Read more >
Known issues with Android Studio and Android Gradle Plugin
Find out about current known issues with Android Studio and the Android Gradle Plugin. ... Running tests using Gradle from the command line...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found