vscode-java
vscode-java copied to clipboard
vscode-java reports "cannot be resolved" errors in Gradle plugin project with mix of Groovy and Java
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
- Clone https://github.com/a01fe/gradle-groovy-java-plugin
cd gradle-groovy-java-plugin/test; ./gradlew javaTaskThis builds the plugin and runs a task in the plugin to verify it compiles and builds successfully- Open the project in vscode and open src/main/groovy/foo/task/JavaTask.java,
vscode-javareports errors on all the references toJavaTaskSpec.
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.
I realized this has already been discussed with @martinlippert in #205
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).
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.
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 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.
Has there been any updates since the last convo on this issue/blocker ?
I have the same problem. So, Has there been any updates?