In this Series
Table of contents
This article compares tools for managing monorepos. Earthly ensures build consistency with a containerized approach that is simpler than Bazel’s. Check it out.
To help you determine what tool would work best for your project, let’s compare five monorepo tools, Bazel, Gradle, Lage, Lerna, and Rush, according to their features, benefits, and drawbacks. We’ll analyze factors like:
- Learning curve
- Ease of adoption
- Build caching
- How well they detect the scope of changes
- Dependency graph visualization
- Ability to constrain dependency relationships within the repository
Let’s dive in.
Google built Bazel to automate software builds and tests, with an aim to make builds reproducible and portable. In other words, for every set of inputs, the same outputs are always produced, regardless of the device on which the build is run.
Some notable features and benefits of Bazel include:
- It’s fast. It’s able to rebuild only necessary file changes by comparing them to previously cached build results. Bazel runs build operations locally by default but you can connect it to a cluster, which makes it even faster.
- It supports local caching of build results. However, it also supports remote caching.
- It supports multiple languages. Bazel also supports multiple platforms such as Linux, macOS, and Windows, for desktop, server, and mobile.
- It can handle large projects. Bazel is reliable when it comes to scaling applications. According to its documentation, it can comfortably handle builds with thousands of source files.
- It can execute a command on multiple devices while developing locally. This is unlike other monorepo tools listed in this article.
- It supports visualization of dependencies between projects and tasks.
Some drawbacks of Bazel include:
- It doesn’t have native support for code generation. Therefore, Bazel requires an external tool for generating code.
- It requires developers to author BUILD files. This is unlike other tools in this article, which can generate build scripts (e.g., Lage and Lerna can analyze package.json files to achieve this).
- It takes time to adopt. Adopting Bazel is a gradual process due to its complexity and requires effort, but it does have exhaustive documentation to guide you through its implementation.
Gradle is an open-source build automation tool. It uses three build phases, known as its Build Lifecycle:
- The Initialization Phase. The environment for the build is set up.
- The Configuration Phase. Task configurations are made, i.e, what tasks run first and in what order.
- The Execution Phase. The determined tasks run according to the order in the configuration phase.
In a monorepo, Gradle is used to create a Gradle build file, which adds dependencies, configurations, and tasks for modules of the repository. You can either create a build file for each module of the repository or a unified build file for the entire repository. The build then runs based on added dependencies.
Tasks in Gradle are logical instructions to be run and can include actions (e.g., copy files or compile), inputs (values, files), and outputs (files as well).
Some benefits and features of Gradle include:
- It runs on JVM (Java Virtual Machine). This makes Gradle friendly for most Java users since build logic can use standard Java APIs.
- It includes Build Scan. This is a good tool for insight into your application’s performance. You can review performance and find out why or when issues occur.
- It’s fast. Gradle reuses previous output to determine what inputs need to be executed. It also allows parallel execution of tasks, like running multiple tasks simultaneously, which makes it even faster.
- It can reuse previous output. Gradle uses Build Caches, allowing it to behave similarly to Bazel.
- It supports major IDEs. Examples include VSCode, Eclipse, Android Studio, IntelliJ IDEA, and NetBeans.
- It supports dependency management.
- It can detect changes in projects and packages. This helps it determine what build or test to run.
Some of the drawbacks of Gradle are:
- It doesn’t provide support for running a command across multiple machines while developing locally. This is unlike Bazel.
Lage (which means “make” in Norwegian) is a build tool that was built by Microsoft, with the aim of improving speed and performance in build processes.
While Lerna and Rush (which are also monorepo tools we’ll cover in a bit) make it possible for you to run your npm scripts one at a time in a topological order (that is, build scripts run first and test scripts run only after they’re completed), Lage tries to minimize the CPU cycles that could be wasted between those two processes. It uses terse pipelining syntax to optimize your build processes, which allocates tasks to available CPU cores rather than waiting and focusing on the order in which the tasks should be run.
Some of the features and benefits of Lage are:
- It’s easy to adopt and get started with. Lage provides you with documentation that’s simpler than Bazel’s or Gradle’s.
- It supports both remote and local build caching. Therefore Lage doesn’t run a task twice, which makes it fast.
- It can detect scope changes by examining a target graph to know what targets are not affected by new changes. This is similar to Gradle.
- It allows you to prioritize tasks. You can schedule tasks in the order with the most optimal run time.
- It comes with a built-in profiler. This lets you visualize your build graphs.
Some of the drawbacks of Lage are:
- It doesn’t provide support for running a command across multiple machines. This is similar to Gradle.
- It only works with npm. Lage can only run npm scripts.
Some of the features and benefits of Lerna are:
- It provides you with detailed documentation for getting started.
- It’s free.
- It provides graph visualization.
- It caches results locally. This is similar to most other tools. It’s also able to run only tasks that have been affected by code changes.
- It makes it possible to share computation caches between developers or CI/CD machines.
- It allows you to run a command across multiple machines. This is unlike Lage.
- It lets you specify the relationship between npm scripts (or targets).
Some of the drawbacks of Lerna are:
- It’s not actively maintained. This is despite its popularity.
- It only works with npm. That is, Lerna doesn’t integrate well with programming languages, tools or platforms. This is unlike Bazel.
Rush is another build tool made by Microsoft. It’s a scalable monorepo manager designed for large teams to handle large repositories. Rush is used by organizations like OneDrive, Windows Store, and Wix.
Microsoft also created Rush Stack which contains components that can be used with Rush, such as:
- API Extractor, which coordinates API reviews.
- API Documenter, which helps to generate your API documentation.
- Rundown, which helps to optimize Node.js process startup times.
Some of the features and benefits of Rush are:
- It’s able to detect changes in dependency in order to run build. This is similar to most other tools.
- It’s free and open source. This is similar to Lerna.
- It supports build caching. However, this is currently an experimental feature, as stated in Rush’s documentation.
- It can automatically generate a Changelog.
Some of the drawbacks of Rush are:
- It doesn’t support graph visualization.
- It doesn’t support multiple languages or multiple platforms. This is unlike Bazel.
As an open source CI/CD framework, Earthly allows you to develop locally and run anywhere. Builds are containerized and language agnostic, and tasks are executed in parallel, which makes it fast. Check out Earthly’s detailed documentation to see how you can get started with it easily.