eclipse-jdtls / eclipse.jdt.ls

Java language server
1.79k stars 399 forks source link

LSP not working with Gradle Kotlin build script DSL #3128

Open lescx opened 7 months ago

lescx commented 7 months ago

Currently, when setting up a new Gradle project with Kotlin as the build script DSL (which is the default), the jdt.ls does not work.

Steps to reproduce

  1. Initialize a new Gradle project with default values and Java target version 17:
$ gradle init

[…]

Enter target Java version (min: 7, default: 21): 17

[…]
  1. Open a .java file in the project in Helix and hover with the cursor over e.g. a class:

image

Expected behaviour

When choosing Groovy instead of Kotlin, the LSP does its job and auto-completions etc. work:

image

Versions

LSP/Helix Logs

~/.cache/helix/helix.log ``` 2024-04-05T23:09:10.398 helix_lsp::transport [ERROR] jdtls err <- "WARNING: Using incubator modules: jdk.incubator.foreign, jdk.incubator.vector\n" 2024-04-05T23:09:10.797 helix_lsp::transport [ERROR] jdtls err <- "Apr 05, 2024 11:09:10 PM org.apache.aries.spifly.BaseActivator log\n" 2024-04-05T23:09:10.797 helix_lsp::transport [ERROR] jdtls err <- "INFO: Registered provider ch.qos.logback.classic.servlet.LogbackServletContainerInitializer of service jakarta.servlet.ServletContainerInitializer in bundle ch.qos.logback.classic\n" 2024-04-05T23:09:10.800 helix_lsp::transport [ERROR] jdtls err <- "Apr 05, 2024 11:09:10 PM org.apache.aries.spifly.BaseActivator log\n" 2024-04-05T23:09:10.800 helix_lsp::transport [ERROR] jdtls err <- "INFO: Registered provider ch.qos.logback.classic.spi.LogbackServiceProvider of service org.slf4j.spi.SLF4JServiceProvider in bundle ch.qos.logback.classic\n" 2024-04-05T23:09:14.603 helix_term::application [WARN] Ignoring a client/registerCapability request because dynamic capability registration is not enabled. Please report this upstream to the language server 2024-04-05T23:09:17.206 helix_lsp::client [WARN] language server failed to terminate gracefully - failed to parse: invalid type: map, expected unit ```
rofe33 commented 6 months ago

The same goes for jdtls on neovim. If the project was initialized with gradle and kotlin as build script DSL. The jdtls doesn't work. However, if the project is created with gradle and groovy jdtls will work, and it will work with mvn. Also if the file is a non-project file, the jdtls will work and tell us.

Versions

Jdtls log

[ERROR][2024-04-09 17:08:08] ...lsp/handlers.lua:535    "Apr 9, 2024, 5:08:08 PM file:///home/user/project/app/src/main/java/org/example/App.java does not resolve to a ICompilationUnit"

Note: I am new to java, gradle... However, for some unknown reasons, after trying groovy. The jdtls worked with build script kotlin. However, I was stuck like 2 hours trying to figure out, why jdtls is not working when I am using gradle.