-
Notifications
You must be signed in to change notification settings - Fork 316
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
External dependencies are not resolved in Intellij #490
Comments
Anyone found a workaround for this until it'll get fixed? Reproduced on my env with bazel |
I added a comment to #252 -- we can't support random genrules, as we rely on getting detailed information from starlark java providers not exposed by genrules. |
I'm not sure this is related. I'm using the same sample project for simplicity, but the issue is with the slf4j dependency not being resolved. If I remove the genrule the issue still persists. I can update the sample project to reflect this if needed. |
@uribwix we have found two workarounds:
I can understand why the plugin may not want to resolve all dependencies in the entire project if you are only working on a subset, but it doesn't seem to be properly detecting which dependencies to resolve. That being said, should bazel only need to resolve/download the dependency once anyway? |
@brendandouglas I updated the sample project to remove the genrule and show that the issue persists. |
Hmm, I tried to reproduce with the new project, but I can't even get it to build. I'm seeing "Worker process did not return a WorkResponse" and "Unrecognized VM option 'CompactStrings'... Could not create the Java Virtual Machine" errors during sync. |
Sorry, I think this has something to do with java toolchain and the bazel version. I've added this to the .bazelrc in the project to suppress this error:
It should build now. |
Our team is having this problem since we started using bazel. I haven't reported the issue because I could not consistently reproduce it, and because we use kotlin, I thought this was some obscure bug related to kotlin support. Our observations:
|
I can't reproduce this on my own test projects, and still can't sync your project @brownry1986, even with that flag. Which OS and bazel version are you using? |
bazel 0.21.0 |
@brendandouglas Following is my environment info: I also have the following in my .bazelrc which is impacting the jdk that is used by bazel: This could explain why you are still getting the CompactStrings error while I am not (since my local jdk is 8). Would it be possible for you to install jdk8 and point your JAVA_HOME to it to attempt to build this sample? However, when I modify the .bazelrc to the following the dependency resolution issues actually goes away: Any ideas why changing the java_toolchain would impact the dependency resolution? |
Following up on this, I opened the Intellij bazel plugin project from a fresh checkout and set my project jdk to 9. Now I am getting the "Unrecognized VM option 'CompactStrings'... error when I try to sync. @brendandouglas are you using a specific jdk when attempting to recreate the issue with my sample project? I would like to sync up my environment with yours as closely as possible. I actually have to add a .bazelrc with the following to build the plugin from command line:
|
I think I'm using java v1.80.91. No idea why changing the toolchain would impact dependency resolution -- I can't reproduce that bit. Adding either set of build flags to my project (java 8 or java 9) fixes the build error and doesn't exhibit the external dependency error. |
@brendandouglas The working set seems to be of importance here (as we can see in brownry1986's workarounds). I made a screencap that illustrates the problem: https://www.youtube.com/watch?v=wHIXIchTPpc As you can see:
But we can not conclude that the flags are the problem. If the original repo contained those flags on master, the problem would be there; if I would then remove the flags after cloning, the issue would disappear. EDIT: more explanations and typo |
Thanks for posting the screencast. That definitely shows the problem. You've set up JDK 9, but the plugin can't find a corresponding project jdk (you can set one up in 'File > Project Structure'). In the video, you can see the 'Sync failed' message, along with this error in the 'blaze problems' view: "Unable to find a JDK 9 ... After configuring in the project structure dialog, sync the project again" |
@brendandouglas It's true there is an error message but that is not what causes the problem. To demonstrate that, I made a capture with JDK 11 installed. This time I also show how the .git folder affects the resolution:
|
Thanks for the extra details, I can reproduce with JDK 11. The problem is that the java_library target (//module:sample-lib) isn't successfully writing out a jdeps file. We rely on jdeps to know which deps are actually required to resolve the source code. Without it, you'll only get deps added to the project libraries for targets in the 'working set' (the set of modified files/directories) -- hence why modifying the root directory fixes the issue. So this is an upstream problem with bazel / JDK 11. Could you file a bug on bazelbuild/bazel? For reference, with JDK 8,
Building with JDK 11, it contains:
|
Thanks for the additional info @brendandouglas . It does appear that the vanilla toolchain has the same deficiency as the jdk11 toolchain. When setting my toolchain to @bazel_tools//tools/jdk:toolchain_hostjdk8 the .jdeps file contains the dependencies. When setting my toolchain to @bazel_tools//tools/jdk:toolchain_vanilla the .jdeps file only contains the library being built. My takeaway is that we need to move away from the vanilla toolchain. Just to summarize for anyone else; there appears to be two paths for loading dependencies into Intellij:
Some java toolchains do not appear to properly produce the jdeps file which would result in these dependencies not being properly loaded into Intellij. Please correct me if the above is not accurate; otherwise I consider this closed (but may file an issue with bazel for the vanilla toolchain). |
Ooh thank you very much for the insight @brendandouglas, I now know how I can track down the issue with our kotlin project. As for the bug in bazel, I did a quick search and found this, so I guess they are aware. |
Please try File | Invalidate Caches | Invalidate and Restart. It work for me. |
Is this still a valid bug? Was this fixed on Bazel's side? |
Coming back to this topic in May 2020. This is still an issue with Bazel 3.0.0 and the latest plugin version (2020.04.13). Providing a --host_java_toolchain=@bazel_tools//tools/jdk:toolchain_java8 also does not fix this problem. The only option that is available as a workaround is to fork the plugin as e.g. in Canva#1 to enforce adding all external dependencies. Btw, who should be fixing this bug? Bazel or the IntelliJ plugin? Or if it cannot be fixed, should there maybe be an official workaround? |
There is a bug in Bazel, that it does not produce proper jdeps files for the IntelliJ plugin, thus breaking the existing API. The only workaround seems to be to force the plugin to treat all files to be part of the working set, and load external dependencies for them. More info at: bazelbuild#490 bazelbuild/bazel#5723 bazelbuild/bazel#6587
I added a fresh fork for forcing the load of external libraries in: https://github.com/gergelyfabian/intellij/tree/v2020.05.08 (basing on 2020.04.13). |
It seems what I wrote about is a different issue with the same symptom. The issue in my case is that there seems to be a bug in the cooperation between intellij plugin and rules_scala. The Scala targets generated by rules_scala do not expose a jdeps interface, hence intellij BlazeJavaWorkspaceImporter cannot find the dependencies for them (assuming they are not in the working set). At the same time I checked, that both proper Java targets get proper dependencies with BlazeJavaWorkspaceImporter and (detected) Scala targets get proper dependencies with intellij BlazeScalaSyncPlugin (Java and Scala use separate mechanisms for import, but both work on their own). The only problem is if a Scala target is misdetected as Java. I created a new issue for this: #1824. |
Description of the issue. Please be specific.I can confirm that this issue still exists for using Java 16. What's the simplest set of steps to reproduce this issue? Please provide an example project, if possible.Exactly like the steps mentioned above: create a Bazel Project + Git + Some external dependencies. After the My best guess: when sync, IntelliJ only looks at information from Git and overrides everything, so those unchanged files will be treated as nonexistent. .blazerc
Version informationIdeaUltimate: 2021.1.3 |
I have similar issue with Bazel plugin with Python. The external dependency can be referenced on first project import, or specifying a new Python interpreter, but the reference was soon gone. Likely due to the Git issue mentioned above. Please advise if there's any workaround. Version information |
This is still a bug in the Bazel IntelliJ plugin. Either of the following patches fixes it: |
As far as I can tell, this is still a bug in IntelliJ 2022 with Java 11 and Bazel 6, with the 2023-01-24 release of the plugin. |
Thank you for contributing to the IntelliJ repository! This issue has been marked as stale since it has not had any activity in the last 6 months. It will be closed in the next 14 days unless any other activity occurs or one of the following labels is added: "not stale", "awaiting-maintainer". Please reach out to the triage team ( |
This issue has been automatically closed due to inactivity. If you're still interested in pursuing this, please reach out to the triage team ( |
External dependencies are consistently not able to be resolved in Intellij with the Bazel plugin.
I have a sample project that demonstrates the issue: https://github.com/brownry1986/BazelIssues
The project builds successfully via command line and syncs successfully in Intellij, however upon opening SampleMain.java the classes imported from external dependencies are not resolved (e.g. org.slf4j.Logger).
The current example uses maven_jar to define the external dependencies, however we see the same behavior when using java_import_external.
The text was updated successfully, but these errors were encountered: