This guide covers how to get started with Gradle Enterprise, with topics such as strategies for incrementally introducing build scans and build cache usage, and key build scan features for improving your development productivity.
This guide does not cover installation of Gradle Enterprise. Please consult the Gradle Enterprise Admin Manual for help with installation.
The remainder of this guide will assume that your installation has a public hostname of
gradle.company.com and has enabled HTTPS.
In order to use build scans and build caching, you must apply the Gradle Enterprise Maven extension to your Maven project.
Add the following configuration block to a new or existing
.mvn/extensions.xml file in your Maven project. The extension will be downloaded automatically from Maven Central once you run your build.
<extensions> <extension> <groupId>com.gradle</groupId> <artifactId>gradle-enterprise-maven-extension</artifactId> <version>1.1.2</version> </extension> </extensions>
You must also indicate the location of your Gradle Enterprise installation.
Add the following configuration block to a new file
<gradleEnterprise> <server> <url>https://gradle.company.com</url> </server> </gradleEnterprise>
You may encounter a warning about an untrusted certificate when connecting to Gradle Enterprise over HTTPS. The ideal solution is for someone to add a valid SSL certificate to the Gradle Enterprise instance, but we recognise that you may not be able to do that. In this case, set the
This is a convenient workaround, but you shouldn’t use it as a long-term solution.
More detailed information about the Gradle Enterprise Maven extension can be found in the Gradle Enterprise Maven extension user manual.
Build scans are a significant innovation in software build tooling. Having centralized and shareable records providing fine grained details and insights of all builds, including local development builds, enables new levels of collaborative debugging and optimization.
Build scans are automatically enabled for all builds, when applying the Gradle Enterprise Maven extension. In order for you to get started properly, you might want to publish only some scans first.
To do so, modify
.mvn/gradle-enterprise.xml as follows:
<gradleEnterprise> ... <buildScan> <publish>ON_DEMAND</publish> </buildScan> </gradleEnterprise>
Then, execute your build as always, but adding the
-Dscan system property to the command-line invocation. As the build completes, the last lines of output will be similar to:
Publishing build scan... https://gradle.company.com/s/3z475bz247h5g
Follow that link to view your build scan.
This section calls out a subset of the things that you can do with build scans.
Search through all of the captured build scans by going to
This view allows searching by various criteria, including top level project name, user name, build outcome, build start time and more. By default, the list is sorted to show the most recent scans first.
Beyond looking for a particular build scan, the listing can provide new insights into the actual builds being run at your organization and by your colleagues. You may find occurrences of previously unknown errors with your build, or that the build is taking longer in certain cases than you expected, or that certain build users are executing more goals than they need to and are therefore subjecting themselves to more build time than they need to, and other previously unknown behaviors.
A key benefit of build scans are the various insights they provide into build performance. Many builds provide different functions for different people and will perform differently on different machines. Having deep performance insights available for every build enables optimizing all corners of the build, for all users.
Use the left navigation menu to visit the
The different tabs focus on different aspects of performance, with the first
Build tab providing a high level build time breakdown and memory information.
Execution plan tab provides an interactive breakdown of the time spent preparing the execution plan of the projects participating in the build. The time shown for each project is the time taken before starting to execute the goals of the project. The most common contributor for a project is downloading plugins and dependencies.
Goal execution tab provides a concise breakdown of the goals that participated in the build, grouped by outcome. This provides a high level view of goal execution and can be used to understand build caching coverage for a particular build.
Build cache tab displays the build cache configuration for the build (e.g. whether a remote cache was used), and lists the individual build cache operations and how long they took. This is particularly useful for analyzing the performance of the remote build cache connection and identifying whether a slow connection is having adverse effects on the build time.
Timeline section (available via the left navigation menu) provides an alternative view onto the goal executions.
This view provides more detail on individual goals (click theicon when hovering over a goal execution).
Build scans make it easy to see which goals are cacheable, and why those that aren’t aren’t. For instance, the
compiler:compile is cacheable for version 3.1 and above of the
Timeline section allows filtering of goal executions via certain criteria, one of which is cacheability.
This is useful when starting with build caching, and as your projects change and evolve, to ensure that you are getting the most out of the build cache.
Gradle Enterprise provides the ability to compare aspects of two build scans.
To compare two scans, use the scan list to find the scans to compare, selecting them by clicking the respectiveor icon. Or, from a scan that you wish to compare with another, click the icon at the top of the scan.
The goal inputs comparison is particularly effective in helping diagnose issues with build caching, particularly cases where reuse was expected but didn’t occur. In such cases, it is common that a non obvious input has actually changed which is preventing reuse. By comparing the inputs of the goal execution from the builds where reuse was expected, the exact input property with a different value between the builds is immediately apparent.
When goal execution outputs are reused in a build, due to build caching, the build scan for that build provides links to the build scan of the origin build.
This feature can be used to provide an audit trail of build outputs, and for validating reuse. It is particularly useful for identifying and diagnosing incorrect reuse, which is typically caused by under declaration of goal inputs. In such cases, the build scan for the origin build can be used to determine the actual input state for cross referencing with the build scan that incorrectly reused the outputs.
To see this feature in action, create two build scans where one reuses output from another. The simplest way to do this is by running exactly the same build twice. View the build scan for the subsequent build and open the timeline visualization. Click on the
FROM-CACHE, and click the
View origin scan link to view the build scan for the build that produced the reused outputs.
The build scan plugin can be configured to publish a build scan for every build invocation, or, always publishing if certain programmatically defined criteria are met, or, always publishing if the build fails. The dedicated Gradle Enterprise Maven extension user manual provides a section outlining how to do this.
It is strongly recommended to configure your builds to always publish build scans, for every build. Collecting build scans for every build yields deeper visibility and insights into how your build is performing and is being used, as well as making features such as tracing reused task outputs more effective.
While the blog post mentioned above is written using a Gradle build as reference, all the custom tags, values and links concepts apply generally to any build systems.
Extending your build scans with tags, values and links is strongly recommended. In particular:
VCS information such as commit identifiers, branch names, etc.
Tags for different types of builds (e.g. CI vs. local)
Links to CI system record of build for CI builds
This adds useful context to your build scans.
Gradle Enterprise provides the “Export API” that can be used to extract, in real-time, the same build event streams that power build scans. This can be used for integrating build data with other systems for custom analysis, for custom dashboards, or other uses.
The video below shows a build duration dashboard built on top of the Gradle Enterprise Export API.
Detailed information, including links to the source code for the demo app above and other samples, can be found in the Gradle Enterprise Export API Manual.
A video of a Gradle Summit 2017 presentation on using the Gradle Enterprise Export API for different kinds of analysis is also available which may provide inspiration.
While the videos above were recorded using Gradle builds as reference, the Export API concept applies to any data captured by Gradle Enterprise, no matter the build tool used to generate the data.
The Gradle plugin for Jenkins prominently displays links to the build scan for any Maven builds that produce build scans. This makes viewing the build scan of CI builds much easier.
Build scans are passive with regard to the build process. That is, enabling build scans does not affect the outcome or outputs of your build. As such, it is generally safe to simply add the necessary configuration to your projects to enable sending build scans to your Gradle Enterprise installation and check it in to version control, enabling it for all users of the build.
The Gradle Enterprise Maven extension will not cause build failures, even when there is no connection available to the Gradle Enterprise server when trying to publish.
The best way to improve the execution time of yours builds is by not executing something that was already executed, and just reuse the product of this initial execution. Build caching allows to potentially save a tremendous amount of build time by fetching the outputs of certain goal executions, from a previous identical execution. Under the hood, a goal is a function that takes some inputs and produces some outputs in a deterministic way. By analyzing the goal mechanics and its inputs, Gradle Enterprise can detect whether a given build tries to execute a given goal with the same inputs as a previous execution, and decide to reuse the already produced outputs instead of recomputing them.
The Gradle Enterprise Maven extension enables using a local on-disk build cache and a remote build cache provided by Gradle Enterprise, that can be used to share the results amongst different machines and users.
The local build cache is enabled by default. In order to fully test the remote build cache provided by your Gradle Enterprise installation, you should temporarily disable the local build cache, and enable storing the outputs in the remote cache.
<gradleEnterprise> ... <buildCache> <local> <enabled>false</enabled> </local> <remote> <storeEnabled>true</storeEnabled> </remote> </buildCache> </gradleEnterprise>
The above configuration disables the local cache, and always pushes outputs to the remote cache, for demonstration purposes. Disabling the local cache is generally not recommended and this should be removed for real usage. We recommend allowing storing of the outputs to the remote cache from trusted build agents only, such as CI machines.
You can now run your build as usual.
If this is the first time your project is being built while using the remote cache, you will not see any reuse from the cache; only uploads to it. If you run the same build again, you should see output from Maven indicating that goal executions were reused from the cache.
Gradle Enterprise provides an overview of the cache activity at
https://gradle.company.com/cache-admin, which you can use to see the effect of running your build against the build cache.
The exact numbers you see will depend on how many cacheable goals your build executed.
Please have a look at the list of cacheable goals supported by Gradle Enterprise.
Cache nodes are the caches that Maven builds connect to. Gradle Enterprise provides a built-in node at
https://gradle.company.com/cache. If you don’t specify any remote cache, this is the node where goal execution outputs will be stored. You can install additional “remote” nodes, potentially on different servers, and connect them with Gradle Enterprise.
Different projects may produce and reuse goal outputs at different rates. As caches are limited in size, with least recently used items being evicted to make space, a project that produces many outputs and is frequently changing may undesirably dominate the cache and result in a low cache hit rate for other projects. Distributing projects across cache nodes may yield higher hit rates.
The effectiveness of using a remote build cache is largely dictated by the speed of network communication between the build and the cache. Using a build cache node that is closer to where the builds are run, or that otherwise has a better network connection to it, may reduce build times by reducing network transfer times.
Nodes can be configured by going to
https://gradle.company.com/cache-admin and navigating to the
In particular, consider increasing the cache size from the default of 1 GB to something in the 10s of GB. The larger the cache, the more it can store, which may increase your cache hit rate.
Reading the dedicated Maven build caching guide is strongly recommended. This guide provides detailed information about build caching in general, including considerations for using it in practice. It also covers how to debug and optimize build cache usage using build scans.
The best roll out strategy depends on your circumstances. A common strategy however is to first enable build cache usage only for CI builds, then later enabling for local development builds. The build cache configuration within a build can be specified dynamically, supporting this kind of usage.
For instance, you can define the
-Dgradle.user.config system property on your CI builds to indicate the location of the
gradle-enterprise.xml file that needs to be used in this case.
Enabling build scans for any build using the remote build cache should be considered a prerequisite. Build scan insights make it considerably easier to debug and optimize build cache usage.
If you are currently using Gradle Enterprise, as part of your trial sign-up or license purchase, you will have received instructions on how to access the priority Gradle Enterprise support channel. If you have any issues with or questions about Gradle Enterprise, please raise a support request.
Gradle Enterprise is constantly evolving with regular updates that add new features and capabilities. The monthly Gradle newsletter is an easy way to stay informed about new releases, features and events.