eclipse.jdt.ls icon indicating copy to clipboard operation
eclipse.jdt.ls copied to clipboard

How to supply module path to JDT.LS when using Java 9 modules?

Open oakad opened this issue 6 years ago • 4 comments

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:

  1. Should not JDT.LS consider all 'classpathentries' from .classpath to be also "modulepathentries"?
  2. 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.

oakad avatar Feb 04 '18 12:02 oakad

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>

fbricon avatar Feb 12 '18 14:02 fbricon

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.

oakad avatar Feb 13 '18 00:02 oakad

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.

fbricon avatar Feb 13 '18 01:02 fbricon

This seems to be fixed with Gradle 7.

mrcjkb avatar Jun 09 '21 22:06 mrcjkb