I'm pretty new to Bazel, and had a quick question regarding building Java libraries using it. I noticed in the "Java and Bazel" page of the Bazel documentation site, there are a handful of "Best Practices" that are listed, as seen here:
https://docs.bazel.build/versions/master/bazel-and-java.html#best-practices
For my Java library, I did as the documentation suggested and add BUILD files to every package in my library, all using a non-recursive glob and a local "java_library" rule. However, in regards to generating a final JAR file, I've been rather stumped. I added one final "java_library" rule to the base BUILD file in the directory root, which lists the local "java_library" rule I have in my top-level package as its only dependency. However, when building JAR files via Bazel the class files of dependencies aren't included unless you create a deployment JAR. For a Java library (not binary), this is less than ideal, as it either means your JAR will contain the class files for EVERY dependency (third-party and local), or no class files at all. So just to give a minimalistic example, assuming you have this directory structure:
src
main
java
BUILD
Library.java
BUILD
And the nested BUILD file contains:
java_library(
name = "java",
srcs = glob(["*.scala"]),
deps = ["@org_apache_commons_commons_lang3//jar"],
visibility = ["//visibility:public"]
)
While the parent-level BUILD file contains:
java_library(
name = "lib",
deps = ["//src/main/java:java"],
visibility = ["//visibility:public"]
)
The compiled Library.class will never make its way into the final JAR unless you compile lib_deploy.jar, and at the point all the class files for Apache Lang3 will be included in the JAR as well. What approach should be taken to include all of the local dependencies, but not the external ones, while still adhering to the best practices? Hopefully this all makes sense. Thanks.
--
You received this message because you are subscribed to the Google Groups "bazel-discuss" group.
To unsubscribe from this group and stop receiving emails from it, send an email to bazel-discus...@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/bazel-discuss/78c80fb4-cd56-42df-981d-48cc9130eeb5%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.
--
You received this message because you are subscribed to a topic in the Google Groups "bazel-discuss" group.
To unsubscribe from this topic, visit https://groups.google.com/d/topic/bazel-discuss/PvssQ709iGw/unsubscribe.
To unsubscribe from this group and all its topics, send an email to bazel-discus...@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/bazel-discuss/bd591488-bd1a-48ce-9b1b-400a385ec4cc%40googlegroups.com.
--
You received this message because you are subscribed to a topic in the Google Groups "bazel-discuss" group.
To unsubscribe from this topic, visit https://groups.google.com/d/topic/bazel-discuss/PvssQ709iGw/unsubscribe.
To unsubscribe from this group and all its topics, send an email to bazel-discus...@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/bazel-discuss/3efcff8c-014b-422b-a1fc-f91cdb540982%40googlegroups.com.
--
You received this message because you are subscribed to the Google Groups "bazel-discuss" group.
To unsubscribe from this group and stop receiving emails from it, send an email to bazel-discus...@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/bazel-discuss/078d59c4-ca68-41ff-b1cf-8d18eec45ce8%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.