-
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
ijwb stores entire bazel workspace as single IntelliJ project #179
Comments
More context: We're migrating a large-ish codebase (300+ projects) from maven to bazel. In some cases, different top-level projects depend on different versions (or "flavors" of the same version) of an open source library. For example, we have one project that depends on guice-4.1, and another that depends on guice-4.0-no_aop. Concretely, what we have is:
The two projects that depend on those jars are unrelated; there's no dependency leakage or anything. Bazel builds cleanly, and correctly; However, if we open a file in Foo that depends on an API that only exists in guice-4.1.jar, IntelliJ marks the API usage in red, and says that it can't find that API. I suspect that this is due to the ordering in the idea workspace.xml file, because I can fix it (or break it) by twiddling that. While I was playing around with trying to come up with a reduced test case, I also discovered that it's possible to get into situations where IntelliJ says everything is fine, but bazel doesn't build. This is an easier case to repro, so I posted that one to github. |
We have no plans for multiple IntelliJ modules per project. At the moment, the best workaround is to use multiple IntelliJ projects per Bazel workspace. You can set the scope of the IntelliJ project to whichever set of Bazel targets constitute a sensible module, in the project view file (Bazel > Project > Open project view file). |
@brendandouglas If we do that, how would we use IntelliJ to refactor? Currently we load all of our Java code into one workspace, so when we refactor, IntelliJ finds all call sites and updates them; if we split that up into multiple projects, refactorings in one project won't find call sites in the other projects, right? This bug seems really bad to me. Refactoring is one of the top features people use IDEs for. The whole point is to do the refactor and verify in the IDE that the whole project compiles without errors. If there's only one classpath for the entire workspace, then there's no way to automatically make changes that affect multiple projects and be sure that they safely compile. |
The problem is that there's a fundamental mismatch between the build units in IntelliJ and Bazel. In IntelliJ, you can only configure settings like java language level on a per module basis. This implies one Bazel target == one IntelliJ module. However Bazel targets operate on lists of files, IntelliJ modules on recursive directories. |
I don't think I understand your point. I agree there is some mismatch between Bazeld and IntelliJ, but that mismatch is not relevant to this bug. Just to clarify, let's walk through the test case Robert posed. The The java_library(
name='project2',
srcs=glob(["src/java/**/*.java"]),
deps=[
"@aopalliance//jar",
"@guice_4_1//jar",
],
)
The But the Your point about recursive directories is interesting but is it relevant to this bug? If Since |
I agree there are cases where Bazel and IntelliJ's build units can be compatible. My point is that there are also many cases where they're not. Any time you have build rules in the same package with conflicting dependencies or build flags, there's no way to correctly include them both in a single IntelliJ project. As things stand, it's pretty much infeasible to autogenerate intellij modules from a bazel project. The only sensible build unit is a bazel target, but:
We could do something like introduce a special kind of bazel rule corresponding to a compilation module, and have the bazel plugin use those to generate modules (would likely require buy-in from the bazel team). We could also allow users to manually specify modules in some other way (e.g. in the .bazelproject file). I suspect we'll eventually implement something along these lines, but not anytime soon (it's a decent amount of work, and there's little demand for it internally). In the meantime, some possible workarounds:
|
Maybe people don't need a tool to automagically map targets into modules. It would be nice to have a rule like:
Which would map into a intellij module. Dependencies would be handled as any jars. This plugin, as it is right now, is impractical for any real use case scenario, IMHO. |
I think the above is a harsher position than I'd take (having used the plugin at YouTube, a year ago, to great effect). But I do think it's a crucial feature to making the IDE experience superlative. It represents a case where the IDE and the command line are substantially out of kilter in their view of reality, and that gap is a problem. I think there are some possible ways out of this, including possibly a code inspector that is much more aware of dependency relationships between targets, and can trigger the symbol-not-found behavior. |
I also think that "little demand for it internally" made a lot of sense when the comment was made, but at this point, those of us considering bazel adoption outside of Google need to know if our use-cases will be understood and taken on board by Google, so I'm really hoping that this question can be re-prioritized in that newer light, and that the "internal" (inside Google) lack of motivation for a thing doesn't always result in it being de-prioritized. |
To add our comments, we wouldn't either mind configuring the modules we want to avoid the problem with mismatch between bazel and a intellij project |
Naive comment: What about using |
Some promising news from the IntelliJ team, at https://blog.jetbrains.com/idea/2019/12/intellij-platform-roadmap-for-2020/ (emphasis mine):
|
@brendandouglas curious how you would have multiple projects for a given Bazel workspace. When I attempt to create a new project with a different |
same question when I use multiple IDEs from JetBrains for open 1 bazel project like Aqua and Intellij |
@alice-ks from https://youtrack.jetbrains.com/issue/IDEA-274168 it looks like you tried to support multiple modules in the plugin using the new IntelliJ project model mentioned above. Did it end up not working out? |
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 ( |
ijwb's use of a single project to represent the entire bazel workspace can result in disagreements between the IDE and bazel as to whether the code compiles properly, which results in more than a little confusion for us internally.
One easily reproducible issue is that in a workspace with two projects, only one need declare a dependency on an external jar and both projects will see the jar as a dependency according to IntelliIJ, though bazel will fail to build. I posted a simple example workspace (bazel doesn't build, but ijwb says everything is fine) on github that illustrates the issue. There's also separate, related issue that we're experiencing internally, where IntelliJ will resolve dependencies in a particular file to jars that are dependencies of an entirely unrelated project that shares no dependencies (transitive or otherwise). Bazel finds the right jars while building and running.
Are there any plans to have more granular classpaths for bazel packages in ijwb?
edit: typos
The text was updated successfully, but these errors were encountered: