You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
Repository navigation
'Cannot be resolved' errors in projects with module-info.java #881
I am not able to get projects that use a module-info.java file to work with VS Code and Java. I've tried both Gradle and Maven.
VS Code p shows me a bunch of "cannot be resolved" errors for any classes called out in the module-info.java file. What I have found is that if I put a module attribute in the classpath, then it will work. However, because I am modifying the classpath file manually, I find that Gradle and Maven will automatically refresh the classpath file and remove my modifications to it, which will bring back the errors.
Is there a proper way to use modules with VS Code and Java? It seems that the problem is due to the fact that there needs to be module path information set in the classpath file in order for Eclipse to be happy, but there is no good way to do with that from Gradle or Maven.
@brunoborges I haven't checked but given this is a Gradle project, I'm not too surprised there might be some issues, as AFAIK, buildship doesn't support java module configuration (I maybe be wrong and that's another issue though).
those are regular classpath entries. If there's a module-info.java, Eclipse JDT requires those required modules to be flagged as modules in their respective classpath entries. I don't know that the Java dependency extension provides some kind of support for Java Modules (i.e. displays the module infos). cc @testforstephen@jdneo@akaroml
This solved the issue with the imports, but now IntelliSense (or whatever should do the job) is not working and I don't have auto-complete in the imports section for any package (javafx.* as well as any of the java.* or javax.*):
This solved the issue with the imports, but now IntelliSense (or whatever should do the job) is not working and I don't have auto-complete in the imports section for any package (javafx.* as well as any of the java.* or javax.*)
Hey @brunoborges Thanks for posting your issue. And especially thanks for sharing your sample project. It's a super useful functional test for the upcoming release of my JPMS plugin: mrJar.
„...But it is weird though since I'd expect the transitive config to actually avoid this problem...“
Notice there are zero error messages in the Problems tab. That's because of mrJar's correct expected handling of the transitive config.
Also notice the contents of the build.gradle is a lot simpler, more concise and much prettier with mrJar. That's because there are way fewer lines of boilerplate than what you need with the original plugins you used.
Please, feel free to try it out. Let me know if it works for you. TIA 👍
I have thought about doing exactly what you're asking about before. I won't rule it out for some point in the future. But I can't commit to exactly when.
No response? If anyone wants to reproduce the problem with Maven, just download a project from start.spring.io and add a module-info.java. You might need to tweak the one that VSCode generates for you. This worked for me in a vanilla Boot/Webflux app with Actuators:
YMMV. I had to delete the tests because VSCode is confused about test dependencies and the module path. And the app was runnable from the command line, but not in the IDE (same incomprehensible error as above).
requires java.instrument; works to run the app in the IDE. But it doesn't, does it, require that? So is it still a bug?
I can't reproduce the problem with the tests, but I think I might have updated VSCode Java Extension Pack to a "pre-release" version, so that might be fixed there.
Activity
fbricon commentedon Apr 13, 2019
Can you share a sample project?
brunoborges commentedon Aug 30, 2019
@fbricon a sample project that can demonstrate this is this one: https://github.com/brunoborges/fx2048
I am facing the same issue.
fbricon commentedon Aug 30, 2019
@brunoborges I haven't checked but given this is a Gradle project, I'm not too surprised there might be some issues, as AFAIK, buildship doesn't support java module configuration (I maybe be wrong and that's another issue though).
@snjeza can you please take a look?
brunoborges commentedon Aug 30, 2019
The Java Dependency Viewer extension correctly loads the classpath:
fbricon commentedon Aug 30, 2019
those are regular classpath entries. If there's a module-info.java, Eclipse JDT requires those required modules to be flagged as modules in their respective classpath entries. I don't know that the Java dependency extension provides some kind of support for Java Modules (i.e. displays the module infos). cc @testforstephen @jdneo @akaroml
snjeza commentedon Aug 30, 2019
@brunoborges could you try the following patch:
brunoborges commentedon Aug 30, 2019
@fbricon I don't think they are regular classpath entries. See the module-info.java
@snjeza I tried the patch and it didn't work: I edited the file, closed the folder and reopened the entire project. No success.
fbricon commentedon Aug 30, 2019
Related upstream buildship issue: eclipse-buildship/buildship#658. TL;DR: don't hold your breath for a fix
snjeza commentedon Aug 30, 2019
@brunoborges could you try the following build.gradle:
brunoborges commentedon Aug 30, 2019
@snjeza do I need to run some command to update the eclipse settings after modifying the build.gradle file ?
snjeza commentedon Aug 30, 2019
@brunoborges you can call the "Java: Clean the Java Language Server workspace" command.
brunoborges commentedon Aug 30, 2019
This solved the issue with the imports, but now IntelliSense (or whatever should do the job) is not working and I don't have auto-complete in the imports section for any package (javafx.* as well as any of the java.* or javax.*):
Auto-complete at method/field level works:
snjeza commentedon Aug 30, 2019
The issue can be reproduced in Eclipse.
snjeza commentedon Aug 30, 2019
@brunoborges you can try the following workaround:
1 remaining item
snjeza commentedon Aug 30, 2019
That is an Eclipse bug. Checking...
snjeza commentedon Aug 30, 2019
Related issue - https://bugs.eclipse.org/bugs/show_bug.cgi?id=550619
lingocoder commentedon Nov 6, 2019
Hey @brunoborges Thanks for posting your issue. And especially thanks for sharing your sample project. It's a super useful functional test for the upcoming release of my JPMS plugin: mrJar.
Notice there are zero error messages in the
Problemstab. That's because of mrJar's correct expected handling of the transitive config.Also notice the contents of the
build.gradleis a lot simpler, more concise and much prettier with mrJar. That's because there are way fewer lines of boilerplate than what you need with the original plugins you used.Please, feel free to try it out. Let me know if it works for you. TIA 👍
brunoborges commentedon Nov 7, 2019
Any chance to incorporate your plugin's functionality into vscode-java extension?
lingocoder commentedon Nov 10, 2019
Thanks for coming back to me @brunoborges.
I have thought about doing exactly what you're asking about before. I won't rule it out for some point in the future. But I can't commit to exactly when.
Excellent suggestion, though! Thanks 👍
dsyer commentedon Oct 18, 2021
FWIW I have the same or similar issues with a Maven project. Should I open a new issue, or just watch this one?
dsyer commentedon Dec 7, 2022
No response? If anyone wants to reproduce the problem with Maven, just download a project from
start.spring.ioand add amodule-info.java. You might need to tweak the one that VSCode generates for you. This worked for me in a vanilla Boot/Webflux app with Actuators:YMMV. I had to delete the tests because VSCode is confused about test dependencies and the module path. And the app was runnable from the command line, but not in the IDE (same incomprehensible error as above).
brunoborges commentedon Dec 8, 2022
This issue will become a larger problem with Spring 3.0
snjeza commentedon Dec 13, 2022
@dsyer could you try to add
to your module-info.java
snjeza commentedon Dec 13, 2022
@dsyer Could you try to add
to pom.xml
dsyer commentedon Dec 13, 2022
requires java.instrument;works to run the app in the IDE. But it doesn't, does it, require that? So is it still a bug?I can't reproduce the problem with the tests, but I think I might have updated VSCode Java Extension Pack to a "pre-release" version, so that might be fixed there.
snjeza commentedon Dec 13, 2022
It works in the same way in Eclipse.
dsyer commentedon Dec 13, 2022
So what? I should raise an issue in Eclipse? Do you happen to have a link?