intellij: " File->Open" does not detect that a project is a bazel project

To help people get started quickly, it’s not uncommon for people to check in .ijwb/.bazelproject files. However, once this is done, there’s no way to actually use this:

  • “Bazel import project” will complain that the file already exists
  • “File->Open…” doesn’t detect that this is a bazel project, so the plugin isn’t enabled
  • “File->Import Project” doesn’t list “Bazel” as an external model.

It seems clunky to check in the project config to a different location and then tell people to point to that.

About this issue

  • Original URL
  • State: open
  • Created 5 years ago
  • Reactions: 10
  • Comments: 23 (4 by maintainers)

Most upvoted comments

I’ve struggled with putting IDE configuration for Bazel projects under version control as well. I’ll get into my workarounds, although I don’t think they’re great.

The Exploring the IntelliJ Bazel Plugin’s Sync Process blog post mentioned above has this to say:

The .ijwb directory is not completely portable. Files like .bazelproject and codeStyleConfig.xml can be shared project-wide, but workspace.xml and .workspace.iml should be user-specific.

In general, extract .bazelproject file out of .ijwb/ to version control it, and follow JetBrains’ recommendations on checking in specific files in the .idea directory.

For the .bazelproject file, it’s somewhat reasonable to put that somewhere else such as ijwb/ijwb.bazelproject, similar to this repo.

For the IntelliJ configuration files, though, I don’t believe anything under .idea/ is going to be used, only directories such as .ijwb/.idea/. I have two approaches, neither of which I think is ideal:

1. Keep IDEA config in .ijwb/.idea/ and check that into version control
You have to instruct people setting themselves up on a repo the first time to

  1. Run rm -rf .ijwb/ (!!!)
  2. Open IDEA and go through Bazel project import using the existing project view file ijwb/ijwb.bazelproject
  3. Close IDEA
  4. Run git checkout .ijwb/ to restore the deleted config files you’ve kept under version control
  5. Reopen IDEA

The upshot is that once they’re set up their IDE configuration will stay consistent with upstream.

2. Put IDEA config somewhere else like .idea/
Again you need to provide some user instructions:

  1. Open IDEA and go through Bazel project import like in the first approach
  2. Close IDEA
  3. Run git ls-files .idea | while read -r file; do mkdir -p .ijwb/$(dirname $file) && cp $file .ijwb/$file; done (or put that in a script and have them run it)
  4. Reopen IDEA

While at least you aren’t telling users to delete a directory, the downside of this approach is that the configuration under .ijwb/.idea/ won’t stay in sync with upstream, so configuration can drift.

All in all, I think approach 1 is the most workable, but it’s obviously not ideal.

@mattgodbolt I’m working on a blogpost to demystify some of these: https://github.com/bazelbuild/bazel-blog/pull/200

We’ll probably surface this in documentation soon as well.