intellij: IntelliJ IDEA 2019.1.3 fails to resolve dependencies
Tldr; “How do I reset ALL plugin state when things go wrong”.
I have been using the bazel plugin for IntelliJ 2019.1.3, bazel 0.25.2, and plugin version v2019.05.13.0.2.
Running bazel build //...
always works and Sync project with BUILD files
always completes successfully.
However, IntelliJ sometimes (sometimes but not always) fails to resolve dependencies like so:
This only happens with dependencies which are being downloaded as jars (not compiled from source) e.g. any maven dependencies.
(We are using the rules_jvm_external
maven_install
rule to download dependencies but this happens with other rules too.)
Although all these dependency jars show up in bazel-REPO_NAME/external/...
, they are not appearing in the ‘External Libraries’ explorer area.
The .ijwb/.idea/libraries
is not being populated with the correct xml entries.
Adding libraries manually through the Project Structure dialog (and pointing to the jar used by bazel) works fine and then the dependencies are resolved fine, but the plugin is unable to do this automatically.
This problem can often be fixed by just adding a comma or whitespace to the BUILD file which causes the plugin to retry the dependency resolution. Resetting this whitespace will cause the problem to reappear, seemingly due to some cacheing. I am looking for a way to reliably reset all the state used by the plugin so that it will retry the external libraries resolution without having to add random whitespace or commas to BUILD files. Things tried so far to no avail:
- File > Invalidate Caches / Restart
- Reinstalling plugin
- Bazel -> Sync -> Sync Project
- Deleting
.ijwb
and reimporting project
About this issue
- Original URL
- State: closed
- Created 5 years ago
- Reactions: 5
- Comments: 19 (4 by maintainers)
I think I’m hitting a similar issue. External dependencies referenced through
maven_install
didn’t have the right jars in the project.Looking into Project Settings > Libraries, I noticed that the path to those binaries were incorrect.
Example from my windows machine: commons-lang3-3.9.jar was referencing a path that didn’t exist.
[Project Root]\external\maven\v1\https\repo1.maven.org\maven2\org\apache\commons\commons-lang3\3.9\commons-lang3-3.9.jar
I noticed that
[Project Root]\external
should have been[Project Root]\bazel-[projectname]\external
instead.As a workaround, I created a symlink from
[Project Root]\external
to[Project Root]\bazel-[projectname]\external
and IntelliJ started working properly.HTH
Can we please re-open this issue? We are seeing frequent syncing issues that are only fixed when making trivial edits to
BUILD
files. It seems the plugin needs to consider the package to be within the working set in order to link dependencies in Intellij.@chaoren I’ve now updated the issue to reflect this but neither of these solutions work. Indeed in the latest version of the plugin for mac there is no option at all to do a non-incremental sync.
Edit to add more detail: after deleting
.ijwb
and reimporting, theSync Project with BUILD Files
completes successfully but all files appear in the explorer as(unsynced)
. At this point the only way I’ve found to trigger them to sync (all the options in the Sync menu don’t work) is by changing the order of dependencies in the BUILD files.Thanks for getting back to us. Unfortunately there are no clear repro steps, but we suspect it could be related to our usage of Kotlin as it may not have received as much test coverage.
.ijwb/.bazelproject
.bazelproject