eclipse.jdt.ls
eclipse.jdt.ls copied to clipboard
How to supply module path to JDT.LS when using Java 9 modules?
I'm playing around with Java 9 modules and rely on gradle generated .classpath
file.
The .classpath
defines the class path entries, but it appears not to affect module path used by the JDT.LS. So, when trying to use JDT.LS with Java 9 module (package which has module-info.java
file present), it is unable to locate any classes belonging to "required" modules.
When core JDK classes are concerned, JDT.LS behaves properly, so I understand the issue is purely related to the module path used by JDT.LS for imported module resolution.
Thus, the questions:
- Should not JDT.LS consider all 'classpathentries' from
.classpath
to be also "modulepathentries"? - If the answer to the above is "no", then how to communicate the proper module path to JDT.LS (I'm using it via vscode extension)? If the answer is "yes", then it is not doing what's expected. ;-)
Update: the issue appears to be specifically with "automatic" modules, that is jar files which have no "module-info" yet "required" as modules nevertheless.
For Java 9 modules, a module
attribute needs to be added for each relevant classpath entry. Because jdt.ls relies on Buildship for its Gradle integration, this needs to handled by that project (cc @donat).
As a workaround, and it's a really not ideal at all, you can try to tweak your build.gradle script so that it adds the module flag to the whole gradle classpath container, as such:
<classpathentry kind="con" path="org.eclipse.buildship.core.gradleclasspathcontainer">
<attributes>
<attribute name="module" value="true"/>
</attributes>
</classpathentry>
Gradle as of right now has no actual support for modules, so "buildship" is not going to be that helpful (even if I wanted to use it).
Your suggestion regarding the classpath attribute is helpful and I will try it out.
As a side question, is there a document somewhere describing the eclipse' .classpath schema (with all possible attributes listed and described)? I was looking around but could not find one in the eclipse' docs.
I don't even know. You're kinda supposed to interact with Eclipse JDT API's so that .classpath is eventually modified, but this is an internal format, IMHO. The fact Gradle directly writes to .classpath files is a hack.
This seems to be fixed with Gradle 7.