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

There is no way to refresh the classpath after adding a library to gradle #3893

Closed
zSynx94 opened this issue Dec 13, 2024 · 12 comments · Fixed by eclipse-jdtls/eclipse.jdt.ls#3349
Assignees
Labels

Comments

@zSynx94
Copy link

zSynx94 commented Dec 13, 2024

I added a new library to my java project (org.lz4:lz4-java:1.8.0) but there is no way to get them indexed again.
I tried gradlew build and gradle --refresh-dependencies but it din't work.

Environment
Operating System: Windows 10 Enterprise LTSC 21H2
Visual Studio Code version: 1.85.2
Language Support for Java(TM) by Red Hat Version: 1.37.0
JDK: Amazon Corretto jdk1.8.0_432
Gradle Version: 4.7

Steps To Reproduce
Update/add dependencies to build.gradle file
Wait for it to update (nothing will happen)

Captures
Image
Image
Image

@zSynx94 zSynx94 changed the title There is no way to refresh the classpath after adding a library to gredle There is no way to refresh the classpath after adding a library to gradle Dec 13, 2024
@snjeza
Copy link
Contributor

snjeza commented Dec 22, 2024

@zSynx94 I can't reproduce the issue. Could you attach a project example reproducing the error?

@linuxhelf
Copy link

i am having the same problem.
Neither the Task "Java: Reload Projects" nor the popup, that appears when changing the build.gradle, which wants to synchronize the classpath works for me.
Only "Java: Clean Java Language Server Workspace", which gets anoying in larger projects.

@snjeza
I have created an example project at https://github.com/linuxhelf/vscode-java-import
Steps to reproduce:

  • Open project and wait for it to build
  • see error in App.java
  • uncomment the org.json import in app/build.gradle
  • error in App.java is still present and cant be fixed by reload

What i found out while creating the example project:
This problem is only present with "java.gradle.buildServer.enabled": "off"
When using the gradle buildserver, both the popup and "Java: Reload Projects" correctly update the classpath.

@zSynx94 are you also using "java.gradle.buildServer.enabled": "off"?

@rgrunber
Copy link
Member

rgrunber commented Jan 6, 2025

@snjeza , are you and others able to confirm the problem also goes away when setting java.configuration.updateBuildConfiguration": "automatic" and restarting VS Code ? (restart is needed because there's another bug where it seems changing the setting isn't respected until VS Code is reloaded). Overall, I noticed I could only reproduce the problem when the setting is set to interactive (popup comes up to ask if you'd like to update, given that a build file was changed) and without the gradle build server (so this is using Buildship).

@linuxhelf
Copy link

@rgrunber seems complicated.... i tried to reproduce your case and it didn't work... and then suddenly it worked

i tried a bit more, if i understand it correctly, it behaves as following

first case (starting with automatic):

  • start with clean workspace & java.configuration.updateBuildConfiguration": "automatic"
  • adding / removing the dependency from build.gradle correctly adds/removes it from the classpath
  • setting to java.configuration.updateBuildConfiguration": "interactive"
  • adding / removing the dependency from build.gradle correctly adds/removes it from the classpath without clickling the popup

second case (starting with interactive)

  • start with clean workspace & java.configuration.updateBuildConfiguration": "interactive"
  • adding / removing the dependency from build.gradle does not adds/removes it from the classpath
  • setting to java.configuration.updateBuildConfiguration": "automatic"
  • adding / removing the dependency from build.gradle does not adds/removes it from the classpath

both times i also tried closing/reopening VS Code, but that did noch change anything for me

so conclusion:
this issue only exists with
"java.gradle.buildServer.enabled": "off" and java.configuration.updateBuildConfiguration": "interactive"
and for java.configuration.updateBuildConfiguration" it takes the value when the workspace was first initialised

@snjeza
Copy link
Contributor

snjeza commented Jan 6, 2025

are you and others able to confirm the problem also goes away when setting java.configuration.updateBuildConfiguration": "automatic" and restarting VS Code ? (restart is needed because there's another bug where it seems changing the setting isn't respected until VS Code is reloaded). Overall, I noticed I could only reproduce the problem when the setting is set to interactive (popup comes up to ask if you'd like to update, given that a build file was changed) and without the gradle build server (so this is using Buildship).

@rgrunber Please see eclipse-jdtls/eclipse.jdt.ls#3349 (comment)

@snjeza
Copy link
Contributor

snjeza commented Jan 6, 2025

@linuxhelf Could you try to set

auto.sync=true

to vscode-java-import/app/.settings/org.eclipse.buildship.core.prefs?

@linuxhelf
Copy link

@snjeza auto.sync=true had no impact for me, only java.configuration.updateBuildConfiguration made a difference

i tried both java.configuration.updateBuildConfiguration automatic and interactive with both auto.sync true and false
and i used Clean Java Language Server Workspace at the start for each combination

@rgrunber
Copy link
Member

rgrunber commented Jan 6, 2025

@snjeza I"m seeing the exact behaviour described in #3893 (comment). Looking into it, it seems to me like auto.sync is enabled when the project is imported with "java.configuration.updateBuildConfiguration": "automatic" being the initial setting and disabled when "java.configuration.updateBuildConfiguration": "interactive" is the initial setting on import.

That probably would explain why changing from interactive to automatic doesn't work, and why going from automatic to interactive updates without waiting for the prompt.

@snjeza
Copy link
Contributor

snjeza commented Jan 6, 2025

and disabled when "java.configuration.updateBuildConfiguration": "interactive" is the initial setting on import.

auto.sync=false is set by buildship by default.

@snjeza
Copy link
Contributor

snjeza commented Jan 6, 2025

That probably would explain why changing from interactive to automatic doesn't work, and why going from automatic to interactive updates without waiting for the prompt.

Right. When auto.sync=true, buildship updates the project without waiting for the prompt. This PR doesn't introduce it.
You can create a new issue if it is a problem.

@rgrunber
Copy link
Member

rgrunber commented Jan 6, 2025

Ok, then I'll evaluate your PR while ignoring that bug. I'd also look back at old issues and see if this has ever been filed before. I'm surprised such an issue would have existed for so long, especially given interactive is the default.

@snjeza
Copy link
Contributor

snjeza commented Jan 6, 2025

Ok, then I'll evaluate your PR while ignoring that bug. I'd also look back at old issues and see if this has ever been filed before. I'm surprised such an issue would have existed for so long, especially given interactive is the default.

The related PR - eclipse-jdtls/eclipse.jdt.ls#2224

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

Successfully merging a pull request may close this issue.

4 participants