emacs-lsp / lsp-java

lsp-mode :heart: java
https://emacs-lsp.github.io/lsp-java
GNU General Public License v3.0
652 stars 90 forks source link

jdtls fails to start after clearing ~/.m2/repository #429

Open udalrich opened 1 year ago

udalrich commented 1 year ago

Describe the bug

After deleting my ~/.m2/repository, jdtls no longer starts. It is looking for a jar in my m2 which no longer exists. The jar is not used in the project that I am working on, but was used in one that I used in the past.

Related discussion: https://emacs.stackexchange.com/questions/76826/jdtls-failing-to-start-for-lsp-java-after-clearing-m2-repository

Note This is a caching issue, so a clean config will not have the problem.

To Reproduce Create a maven project that uses org/projectlombok/lombok/1.18.22/lombok-1.18.22 Edit a Java file in that project. Create a maven project that does not use that version of Lombok. Edit a Java file in that project. Delete ~/.m2/repository In the second project, run mvn install so that all dependencies for that project are downloaded. Open emacs and edit a file in the second project. Start lsp-java if not set up to do that automatically. Select i or . when asked to import the project.

You will get a message that jdtls exited, asking if you want to restart it. Restarting will give you the same error message. The jdtls::stderr buffer will contain many instances of

Process jdtls stderr finished
Error opening zip file or JAR manifest missing : /Users/me/.m2/repository/org/projectlombok/lombok/1.18.22/lombok-1.18.22.jar

Expected behavior jdtls starts without errors and lsp-java works.

Screenshots N/A

Logs Please include the debug stack trace (if there is an error) and the content of Messages buffer with lsp-print-io set to t in case the bug is related to client->server communication.

End of messages (sanitized):

[2023-04-17 11:02:04.377] Set up lsp for /Users/me/projects/some-project/src/main/java/com/example/Example.java
[2023-04-17 11:02:04.400] my-java-mode-hook completed
[2023-04-17 11:02:04.659] using config for config_mac
[2023-04-17 11:02:05.015] LSP :: Connected to [jdtls:8457/starting /Users/me/projects/some-project].
[2023-04-17 11:02:06.471] LSP :: jdtls has exited (exited abnormally with code 1)
[2023-04-17 11:02:08.700] Server jdtls:8457/starting exited (check corresponding stderr buffer for details). Do you want to restart it? (y or n) y
[2023-04-17 11:02:08.736] using config for config_mac
[2023-04-17 11:02:09.113] LSP :: Connected to [jdtls:8578/starting /Users/me/projects/some-project].
[2023-04-17 11:02:09.962] LSP :: jdtls has exited (exited abnormally with code 1)
[2023-04-17 11:02:11.900] Server jdtls:8578/starting exited (check corresponding stderr buffer for details). Do you want to restart it? (y or n) n

lsp-log

The following clients were selected based on priority: (server-id jdtls, priority 0)
Found the following clients for /Users/me/projects/some-project/src/main/java/com/example/Example.java: (server-id jdtls, priority 0)
The following clients were selected based on priority: (server-id jdtls, priority 0)
Found the following clients for /Users/tda0106/projects/some-project/src/main/java/com/example/Example.java: (server-id jdtls, priority 0)
The following clients were selected based on priority: (server-id jdtls, priority 0)

jdtls::stderr

Error opening zip file or JAR manifest missing : /Users/me/.m2/repository/org/projectlombok/lombok/1.18.22/lombok-1.18.22.jar
Error opening zip file or JAR manifest missing : /Users/me/.m2/repository/org/projectlombok/lombok/1.18.22/lombok-1.18.22.jar

Process jdtls stderr finished

This repeats many times.

sincebyte commented 1 year ago

Maybe you cloud use lsp-workspace-folders-remove and remove the project which is no needful. And use lsp-workspace-restart for restart your jdtls.