vscode-java icon indicating copy to clipboard operation
vscode-java copied to clipboard

vscode-java reports "cannot be resolved" errors in Gradle plugin project with mix of Groovy and Java

Open a01fe opened this issue 5 years ago • 9 comments

In Gradle plugins implemented with a mix of Java and Groovy, vscode-java reports "cannot be resolved" errors in .java files that reference classes defined in .groovy files. Gradle can compile and build the plugin successfully.

Environment
  • Operating System: macOS 10.15.4
  • JDK version:
    openjdk version "13.0.2" 2020-01-14
    OpenJDK Runtime Environment (build 13.0.2+8)
    OpenJDK 64-Bit Server VM (build 13.0.2+8, mixed mode, sharing)
    
  • Visual Studio Code version:
    Version: 1.45.0-insider
    Commit: abb4a35cfc26102f93fd00df7b59ce1a19c2017a
    Date: 2020-04-28T05:34:21.109Z (20 hrs ago)
    
  • Java extension version: 0.60.0
Steps To Reproduce
  1. Clone https://github.com/a01fe/gradle-groovy-java-plugin
  2. cd gradle-groovy-java-plugin/test; ./gradlew javaTask This builds the plugin and runs a task in the plugin to verify it compiles and builds successfully
  3. Open the project in vscode and open src/main/groovy/foo/task/JavaTask.java, vscode-java reports errors on all the references to JavaTaskSpec.

a01fe avatar Apr 29 '20 02:04 a01fe

Unfortunately, it's a known limitation of the JDT compiler. It only knows about Java classes, not from other languages. Getting a working groovy support would require loading the Groovy Eclipse plugin and its patched JDT compiler instead of JDT, in the Java Language server. It might or might not be doable, but this is definitely a task that will require some contributions from the community. cc @martinlippert, in case he's interested.

fbricon avatar Apr 30 '20 10:04 fbricon

I realized this has already been discussed with @martinlippert in #205

fbricon avatar Apr 30 '20 10:04 fbricon

Yepp, discussed back then and I don't think anything has really changed since then. However, feel free to get in contact with the people working on groovy-eclipse (https://github.com/groovy/groovy-eclipse) to further discuss this with them (I think @eric-milles is the one).

martinlippert avatar Apr 30 '20 10:04 martinlippert

Joint compilation for Groovy and Java for LSP has been discussed. Also, there may be Groovy LSP implementations already, but I am unsure about their support for joint compilation (inter-dependency) of Groovy and Java sources.

eric-milles avatar Apr 30 '20 16:04 eric-milles

Thanks for your comments! After reading through the linked issues it appears that separate Groovy and Java language servers would be the cleanest way to go. The downside is that crossed Groovy/Java references likely wouldn't work. Is this because language servers would need to know the others contributions to classpath and the there's no established protocol for them to share this?

a01fe avatar Apr 30 '20 18:04 a01fe

@a01fe I think it depends on the structure of your project. If you have one-way references only (always from Java to Groovy code or vice versa), you should be able to set this up with separate language servers. But having real cross-references in both directions, you would need a compiler that can compile both, I think.

martinlippert avatar May 01 '20 20:05 martinlippert

Has there been any updates since the last convo on this issue/blocker ?

tekleayele avatar Oct 11 '21 14:10 tekleayele

I have the same problem. So, Has there been any updates?

AaaCabbage avatar Aug 04 '22 03:08 AaaCabbage