In summary, the data and analysis indicates clearly that Gradle is a better choice than Bazel for most JVM projects. We will provide an equivalent comparison for Android projects in a follow up article.
Bazel is an open-source build and test tool similar to Make, Maven, and Gradle. It uses a human-readable, high-level build language. Bazel supports projects in multiple languages and builds outputs for multiple platforms. Bazel supports large codebases across multiple repositories, and large numbers of users.
Bazel supports multiple build files and multiple targets per BUILD file, allowing for builds that are more incremental than Maven's. Maven takes charge of steps for the deployment process. Bazel does not automate deployment. Bazel enables you to express dependencies between languages.
Gradle is based on a graph of task dependencies – in which tasks are the things that do the work – while Maven is based on a fixed and linear model of phases. With Maven, goals are attached to project phases, and goals serve a similar function to Gradle's tasks, being the “things that do the work.”
Disclaimer: I work on Bazel and I'm not intimately familiar with Gradle. However, one of my coworkers wrote up a comparison of the two systems, which I will paraphrase here:
Bazel and Gradle emphasize different aspects of the build experience. To some extent, their priorities are incompatible - Gradle’s desire for flexibility and non-obtrusiveness limits the restrictions it can place on build structure, while Bazel's desire for reliability and performance necessarily enforces non-negotiable restrictions.
Gradle does value the same principles that Bazel does, i.e. the Gradle team pays great attention to performance (incremental builds, parallelized configuration and execution, the Gradle daemon), correctness (content-based “up-to-date” checking), and reproducibility (rich support for declarative syntax, dependency versioning, explicitly declared dependencies). And Bazel respects the need for flexible project layouts.
The nuance is that Gradle wants to promote good practice while Bazel wants to require it. Gradle aims for a middle ground between the Ant experience (freedom to define your own project structure with incoherent results) and the Maven experience (enforced best practices with no room for varying project needs). Bazel believes that flexible project support is possible without sacrificing the strong guarantees that enable its powerful workflows.
Neither philosophy is more “correct” - whichever tool best suits a project depends on that particular project’s values.
Gradle is a highly flexible system that makes it easy for users to construct complete, reliable build flows with minimal constraints on how they organize their projects. It does this by supplying powerful building blocks (e.g. automatic dependency tracking and retrieval, tightly integrated plugin support) with a generic, Turing-complete, scripting interface that can combine these blocks however the users wants.
Gradle emphasizes the following features:
Bazel evolved out of the need to build internal Google projects reliably and efficiently. Because Google’s development environment is unusually large and complex, Bazel offers unusually strong guarantees about the integrity of its builds and unusually low performance overhead in achieving them.
This provides a foundation for powerful development workflows built around reproducible builds, where a “build” becomes an abstract entity that can be referenced, repeated, passed around to different machines, and passed to arbitrary programs and services such that every instance is known to be exactly the same.
Bazel emphasizes the following features:
As article links tend to die, here is a summary of the Gradle Team's views on Bazel (most are directly lifted from the article, which was published in March 2015):
It was designed to solve a problem unique to Google; a massive monolithic codebase (hundreds of millions of LOC).
The parallelisation advantage Bazel currently provides will be matched by "our upcoming new configuration and component model" (bear in mind the article date here).
Bazel does not have a high level declarative build language that makes the build easy to use for developers. At Google this can be compensated with a specialized service team that owns the build tool.
Bazel is not built for extensibility (although the Bazel development team have since countered this with assurances that they are working on extensibility).
Speed is optimised around the idea that all transitive dependencies are stored in one big repo; all libraries and tools are checked in to this central repository. Most Enterprises have more distributed dependency management requirements.
Bazel is *nix only, it does not run on Windows. This eliminates a large number of potential Enterprises.
No plugin ecosystem.
Gradle is mostly used in JVM eco system (Java, Ggroovy, Scala, Kotlin ...). If your project is in this area, and you have to ask the question, Gradle or Maven would be a better choice. To troubleshoot a Gradle build, you'll wrangle with Java and JVM ecosystem only.
Bazel at the heart have ability to detect incremental changes(as well as distributed build cache) and allow you to react, apply plugins/rules to achieve incremental builds. To setup and maintain this required a bit of knowledge in CPP, Java and Python(Skylark) and System Admin's knowledge too. Again if you have to ask the question I think Gradle or Maven would be a cheaper investment. With Bazel you can build whichever languages, in whichever way you define, more power, but at a cost.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With