NOTE: This project is deprecated and no longer maintained.
BUILD File Generator generates Bazel BUILD files for Java code.
- It reads all
.java
files, and extracts the class dependency graph. - Computes the strongly connected components of the graph.
- For each component, creates a
java_library
rule.
Having all sources in a single BUILD rule doesn't allow Bazel to parallelize and cache builds. In order to fully benefit from Bazel, one must write multiple BUILD rules and connect them.
This project automates writing granular BUILD rules that allow Bazel to parallelize and cache builds.
It's useful to quickly try out Bazel on your project as well as to periodically optimize your build graph.
BFG is composed of two general components
- Language specific parsers
- The BFG binary
The parsers read your source code and generate a class dependency graph in the form of a protobuf. To generate your BUILD files, you pass the generated protobuf into the BFG binary.
Suppose your project's Java code is in core/src/main/java/
and
core/src/test/java/
.
bazel run //lang/java/src/main/java/com/google/devtools/build/bfg:JavaSourceFileParserCli -- --roots=core/src/main/java,core/src/test/java $(find core/src/main/java/ core/src/test/java/ -name \*.java) > bfg.bin
The output is a serialized [ParserOutput] (
) protoTODO(bazel-devel): add explanation and valid example arguments.
bazel run //src/main/java/com/google/devtools/build/bfg -- --buildozer=$BUILDOZER --whitelist=$YOUR_JAVA_PACKAGE < bfg.bin
We currently support Java projects. The next language on our roadmap is Scala.
We use a bazel-deps
to manage Maven jar dependencies. All of our dependencies are listed in
maven_deps.yaml
. bazel-deps
provides tools to manage
dependencies in that file and generates the Bazel build files for them in
thirdparty/jvm/
.
To use bazel-deps
, use the wrapper scripts in dev-scripts/dependencies/
.
Don't edit the files under thirdparty/jvm/
by hand.
To add or update a dependency, run
./dev-scripts/dependencies/add-dep.sh MAVEN_COORD
, where MAVEN_COORD
is the
Maven coordinate of the dependency, such as com.google.guava:guava:23.0
.
Add the --scala
option if it is a Scala dependency.
After running this, you'll see changes to maven_deps.yaml
and one or more
files under thirdparty/jvm
. Add and commit all of those changes. Similarly,
if you run add-dep.sh
with a new version of an existing dependency, it will be
updated in maven_deps.yaml
and any changed indirect dependencies will be
reflected in the generated files.
You can also edit maven_deps.yaml
manually. You will need to do this to
remove a dependency, or to add exclusions to a dependency's dependencies. After
making changes, run ./dev-scripts/dependencies/generate.sh
to rebuild the
generated files, and commit the changes to the generated files.