Bazel - Align package groups into modules
Is there a way to group a set of packages in a Bazel workspace like they were traditional Java packages? I have seen some organization use rules_gradle to map collections of directory-nested targets into Modules as divisible by the IntelliJ windows tab. The biggest issue with the current setup is importing dependencies is a exercise in frustration. I need to EXPLICITLY add each dependency i want to use to the BUILD file, resync, then use it. Finding relevant code is impossible under this setup, unless i import every single JAR I have, then perform cleanup. I understand that the traditional Java package structure is pretty irrelevant in the Bazel world, but it's seems that IntelliJ features are deeply tied to that mindset still.
I would think that project views could handle this, but it's failed to do so, or at least there is no good example repo. Lot of bazel setup's are internal repo's, with little knowledge flowing back into the community. If anyone has good idea's on how to do this, that would be great.
Related Tickets
Please sign in to leave a comment.
Hi Mark Vibbix
Answering your question, you cannot make Bazel treat a directory tree like a single Java module that “just sees” everything without declaring deps. Bazel requires explicit dependencies for builds.
Result: You still declare deps, but at a higher level and in fewer places; IntelliJ navigation works via exported transitive deps, approximating traditional modules without fighting Bazel’s model. I have a very basic example of it, let me know if you want to take a look at it.
Thanks for the quick response Monica.
A very basic example would be great. As of now, i am I am using the https://github.com/bravit/bazel-java-kotlin-sample example that was mentioned in the release notes for the Bazel plugin, but it's flexible layout seems to break the maven-style package auto-detection feature in the newer releases of the Bazel plugin.
I guess what best describes what I am looking for is IDE-Scoped / Developer-scoped dependencies. An example of this would be Spring Boot Tools or Reactor Debug. They exist only when running in the IDE.
It seems some parts of BazelProject get close to this.
Hi Mark Vibbix
Here's the project I have: https://github.com/moniss/BazelAlikeJava.git. You can check against BazelProject explanation, as the project I'm sharing makes use of *.bazelproject.
I hope it helps!