This categorized list of Gradle features will help you understand some capabilities of Gradle for your use cases. Check out the user manual for reference and Gradle guides for getting started.
Table of Contents
Running Gradle Builds
Authoring Gradle Builds
Ecosystem-specific Features
Features for Developer Tool Providers
Running Gradle Builds
If a build's Test tasks are configured to use a different version of Java than what Gradle was started with and parallel execution is enabled (running with -parallel or when org.gradle.parallel=true), Gradle may hang when multiple Test tasks are executed at the same time. We use gradle (Version 1.12) as a build tool. To run the unit test parallelly using gradle we use the bellow script in every projects under test task. MaxParallelForks = Runtime.runtime.availableProcessors.
These features affect developers running Gradle builds, and can be taken advantage of by anyone running Gradle.
Performance
Incremental Builds
Gradle checks in between build runs whether the input, output or an implementation of a task has changed since the last build invocation. If not, the task is considered up to date and is not executed. Gradle also considers the configuration of the task as part of its input.
Build Caching
If a task has already been executed on another computer, Gradle can skip the execution locally, and instead load the task's outputs from the build cache. The typical use case is to let CI builds push to a shared build cache, and allow developers to pull from it. A local build cache is also available to reuse task outputs produced earlier on the same machine. Several plugins including Android, Kotlin, C++, and Scala also support task level caching.
Incremental Subtasks
When Gradle discovers that the input or output of a task has changed between build runs, the task is executed again. The task can use the incremental API to learn what files exactly have changed. With this information the task may not need to rebuild everything.
Incremental Annotation Processing
Incremental annotation processing significantly increases the effectiveness of incremental compilation when supported annotation processors are present.
Compiler Daemon
When you need to fork the compilation process, Gradle creates a daemon process that is reused within a multi project build. This provides a dramatic speed improvement for the compilation process.
Parallel Execution
Gradle allows parallel execution of tasks and intra-task work through a Worker API. Parallelism is very fine-grained, resulting in faster performance.
Parallel Download of Dependencies
Gradle will download both dependency metadata (typically `pom.xml`) and artifacts in parallel. This is done on demand, only when the artifacts are actually required.
Task timeouts
Every task has a timeout property which can be used to limit its execution time. When a task reaches its timeout, its task execution thread is interrupted and allowing the build to finish.
Build Scans
Web-based Build Visualization
Understand what happened in your build via a rich web interface instead of a text console and text files. Build scans provide more information, more effectively.
Collaborative Debugging
Share build scans with colleagues to efficiently solve problems and improve things together. Share entire scans or links focussed to a particular aspect of the build such as a logging output line.
Extend and Customize
Add your own data to build scans as tags, values and links. Integrate build scans into your toolchain.
Fine-grained Build Comparison [Gradle Enterprise]
Build scan comparison quickly highlights differences between builds, such as dependencies and their versions, making root cause analysis much faster.
Track and Export History Across all Builds [Gradle Enterprise]
Track key build metrics for all of your builds, including local development builds and not just CI builds. Understand trends and export build scan data to storage of your choosing.
Execution Options
Continuous build
When a Gradle task is run in continuous mode, Gradle automatically watches for changes of the input of this task. Whenever the input changes, the task it automatically executed. You can run multiple tasks continuously in a multi-project build.
Composite builds
Composite builds allow you to include other independent projects so that you can, for instance, develop an application and a library that it depends on simultaneously. They build in parallel by default, and can be nested.
Task Exclusion
You can exclude any task from being run. When you exclude a task, all tasks this task depends on are also automatically excluded if they have no other dependencies.
Dry Run
Run a build to see which tasks actually get executed without executing the task actions.
Continue Execution After Failures
Does not stop as soon as the first failure is encountered. Executes every task to be executed where all of the dependencies for that task completed without failure. Enables discovery of as many failures as possible in a single build execution with a very nice aggregated error report at the end.
Fail Fast Test execution
Although continuing after a test failure is the default in Gradle, you can set the `--fail-fast` flag or configure `failFast=true` for a Gradle build to fail and finish as soon as one of your tests fails.
Sync Dependency Cache with Repository
Gradle has a `--refresh-dependencies` option to ignore all cached entries for resolved modules and artifacts. A fresh resolve will be performed against all configured repositories, with dynamic versions recalculated, modules refreshed, and artifacts downloaded. However, where possible Gradle will check if the previously downloaded artifacts are valid before downloading again. This is done by comparing published SHA1 values in the repository with the SHA1 values for existing downloaded artifacts.
Authoring Gradle Builds
These features affect build authors and those responsible for developer productivity.
Build Logic is Testable Code
Groovy DSL
Ideally, a Groovy build script looks mostly like configuration including setting some properties of the project, configuring dependencies, declaring tasks, and so on. That configuration is based on Groovy language constructs.
Kotlin DSL
Gradle’s Kotlin DSL provides an alternative syntax to the traditional Groovy DSL with an enhanced editing experience in supported IDEs, with superior content assist, refactoring, documentation, and more.
Gradle Init Plugin
The Gradle Build Init plugin can be used to create a new Gradle build of various types (Java application, Java library, Groovy library, Kotlin application, etc) or convert existing builds (e.g. An Apache Maven build) to be Gradle builds.
Dependency Management
Transitive Dependencies
One of the main benefits of using a dependency management system is managing transitive dependencies. Gradle takes care of downloading and managing transitive dependencies.
Custom Dependency Scopes
Don't be limited by a predefined set of dependency scopes (compile, runtime, etc). Gradle allows you to define arbitrary dependency scopes. For example for integration tests that you may model in your build, to provision toolchains you need in your build, etc …
File Based Dependencies
Not all dependencies are available from external repositories. Declare dependencies on file system resources when using a managed dependency isn't practical or when migrating legacy builds.
Custom Repository Layout
Declare repositories with custom layouts. With custom layouts you can effectively treat nearly any file system directory structure as an artifact repository.
3rd Party Dependency Cache
Dependencies from remote repositories are downloaded and cached locally. Subsequent builds use cached artifacts to avoid unnecessary network traffic.
Maven and Ivy Repository Compatible
Gradle is compatible with the POM & IVY Metadata formats and can retrieve dependencies from any Maven or IVY compatible repository. Ivy metadata is exposed to custom resolution rules allowing you to filter on artifact branch, status or other custom metadata information.
Native BOM support
Platform definitions, aka Maven BOM dependencies are natively supported, allowing importing things like the Spring Boot platform definition without using an external plugin.
Dynamic Dependencies
Resolved dependency versions can be dynamic. Gradle supports the Maven snapshot mechanism but is more powerful than that. You can declare a dependency on the latest release, most current development version, or even the latest 5.X build.
Dynamic Dependency Locking
Allow builds to remain deterministic and reproducible when using dynamic dependency versions.
Dynamic Dependencies Selection Rules
Define custom rules to select a specific version when a dynamic dependency is declared. The rules can be based on names and version but also extended metadata like branch or status. The rules can also differ based on the environment the build is happening, e.g. local or CI.
Dependency Version Alignment
Dependency alignment allows different modules in a logical group (Jackson modules, for example) to be aligned to the same version.
Version Conflict Resolution
By default, Gradle resolves conflicts to the newest requested version. You can customize this behavior.
Substitution of Compatible Libraries
Use dependency substitution rules to identify that dependency should be treated as similar. For example log4j and log4j-over-slf4j. Tell Gradle that only one should be selected and use Gradle conflict resolution to pick the newest version from both of them. Similar use cases are situations where you have libraries like spring-all and spring-core in dependency graph. Without properly modelling this the proper behavior of your application depends on the very fragile order in your classpath.
Enhanced Metadata Resolution Support
Dependency metadata can be modified after repository metadata is download but before it is chosen by Gradle as the final resolved version. This allows the creation of custom rules to do things like declare modules as changing (or snapshot) versions, or use a custom status scheme.
Replacement of external and project dependencies
Dynamically replace external dependencies for project dependencies and vice versa. Especially helpful when only a subset of your modules are checked out locally.
![Gradle Parallel Task Execution Gradle Parallel Task Execution](/uploads/1/3/4/5/134518615/609720784.jpg)
Standardizing Gradle Across Teams
Self-Provisioning Build Environment
With the Gradle wrapper the Gradle build environment is auto-provisioned. Furthermore you can determine which version should be used to build your project.
Version Controlled Build Environment Configuration
Important parameters for configuring the build environment can be stored in version as part of your project. No need for the developers to set them up manually. This includes the Gradle version to be used, the configuration for the JVM running the build and the JDK to be used for running the build.
Custom Distributions
Every Gradle distribution has an init.d directory in which you can put custom scripts that pre-configure your build environment. You can use this to apply custom rules that are enforced, to provide build-in set up tasks for developers, and so much more. Together with the Gradle wrapper you can easily distribute those custom distributions.
Software Domain Modeling
Domain Object Containers
Every domain object describing your build, be it repositories, source directories, plugins or dependencies are stored in a responsive container that you can register listener with. You have full control over what particular builds scripts add to a build. Augment or modify what has been added, let the build fail or issue a warning. You can add define dependencies that are only added for example if a build adds a particular plugin. A very, very powerful feature.
Publishing Multiple Artifacts
Gradle can publish multiple artifacts per project with different metadata. Be it an API and an implementation jar, a library and a test-fixture or variants for different Java platforms.
Advanced Task Ordering
Beyond having full control about the dependencies that are created between tasks, Gradle has powerful language constructs to describe execution order between tasks even if tasks depends not on each others output. This can be modelled with shouldRunAfter and mustRunAfter relationships.
Task Dependency Inference
Gradle objects are aware of which tasks produce certain content. For example, the object representing the Java binary directory knows that the compile task produces the binaries. Any task that has the Java binary directory as input will automatically depend on the compile task. It does not need to be declared manually. This makes the build easier to maintain and more robust.
Task Finalizers
Tasks can be assigned to finalize another tasks similar to a finalizer clause in Java. They are always run after another task is executed, regardless whether this task fails or not. This is very powerful for example when doing lifecycle management for containers or databases.
Dynamic Task Creation
Sometimes you want to have a task whose behavior depends on a large or infinite number value range of parameters. A very nice and expressive way to provide such tasks are task rules.
Fine Grained Build Event Listener
Gradle allows you to hook into every part of the build configuration and execution lifecycle for injecting custom behaviour, extracting information, adding additional logging and a tons of other use cases.
User Based Behavior Injection
You can put custom listeners into your Gradle user home that hook into every Gradle build that is executed on your machine. With the lifecycle listeners described above you can add whatever custom behavior you want to individualize your build experience. For example adding and configuring the Gradle announcement plugin that pops up a window when the build is finishing or failing or adding a special repository that your are just using personally. Automotive meter es 585.
Per Build Behavior Injection
Similar to user based behavior injection, you can also specify on the command line additional listeners that hook into a build. This can be very helpful for example if you want your CI build to have specific behavior (e.g. fail if a non-standard repository is used).
Gradle Plugin Authoring
TestKit for Functional Testing
Programmatic execution of build through API agnostic of test framework. Inspection of build outcome and output. Cross-version compatibility testing. Debugging the build under test from the IDE.
Custom Command Line Options
The task API supports a mechanism for marking a property to automatically generate a corresponding command line parameter with a specific name at runtime.
Ecosystem-specific Features
Features specific to JVM, Android, C++, Swift, Objective C, and other ecosystems.
JVM Applications
Incremental Compilation for Java
Whether a the source code or the classpath changes, Gradle detects all classes that are affected by the change and will only recompile those.
Compile Avoidance for Java
If a dependent project has changed in an ABI-compatible way (only its private API has changed), then Java compilation tasks will be up-to-date.
Built-in Groovy Support
The Groovy plugin extends the Java plugin to add support for Groovy projects. It can deal with Groovy code, mixed Groovy and Java code, and even pure Java code.
Built-in Scala Support
The Scala plugin extends the Java plugin to add support for Scala projects. It can deal with Scala code, mixed Scala and Java code, and even pure Java code.
Built-in Support for JVM Code Quality Tools
The Gradle distribution includes plugins for Checkstyle, CodeNarc, PMD, JaCoCo, and other tools.
Packaging and Distribution for JARs, WARs, and EARs
Gradle comes out-of-the-box with tools to package JVM-based code into common archive files.
Publishing to Maven Repositories
Publish artifacts to Maven repositories like Bintray or Maven Central.
Publishing to Ivy Repositories
Publish artifacts to Ivy repositories, with customizable directory layouts.
Ant Integration
You can deeply integrate any default, optional, or custom Ant task. You can also import Ant builds at runtime, and even partially replace Ant targets dependent on Gradle tasks.
Android Applications
Official Android Build Tool
The Gradle Android Plugin and Android Studio are official tools provided and maintained by the Android SDK Tools team. To learn more about using Gradle with Android, please reference the Android Developer Documentation for Gradle.
Native Applications
Build C/C++/Obj-C/Obj-C++/Assembler
Gradle has built in support for compiling and linking programs using Assembler, C/C++ and Obj-C/C++. Gradle can build shared and static libraries and executables.
Model variants of a native component
Easily model variants of a native component like support for different ABI's, OS, build types, etc.
GCC Support
Gradle supports building with GCC4 on Linux, Windows (with Cygwin and MingW) and Mac OS X.
Clang Support
Gradle supports building with Clang on Linux and Mac OS X.
MS Visual C++ Support
Gradle supports building with Microsoft's Visual C++ compiler on Windows. (VS 2010, VS 2013, and VS 2015 supported)
Generates Windows Resources
Gradle uses Microsoft's resource compiler to build Windows resource script files into your application.
Parallel Compilation
When building native code, Gradle divides the compilation step into parallelizable tasks and executes them in a shared resource pool. This speeds up the single project case and ensures that Gradle does not consume too many resources in parallel multi-project builds.
Precompiled Headers
Gradle makes it easy to use precompiled headers when building your software. Precompiled headers can speed up compilation times if your project has many header files that are included in most of your source code. Precompiled headers is a compiler-specific optimization to cache an already parsed version of your headers.
Build mixed language binaries
Gradle can build separate languages (e.g., Assembler and C) and link them into a single executable or library.
CUnit Test Support
Gradle supports testing C applications with CUnit.
GoogleTest Support
Gradle supports testing C++ applications with GoogleTest.
Cached Compilation
When building native code, Gradle uses the build cache to avoid recompiling code that hasn't changed. Compiler arguments, macro definitions and headers are all taken into account when reusing cached compilation.
Features for Developer Tool Providers
These features will be most interesting for those working on IDEs and continuous integration systems, but there are many other creative uses.
Embed Gradle with Tooling API
SDK for embedded usage
Provided by the Gradle Tooling API
Version agnostic
The Gradle tooling API is back and forward compatible. With a particular version of the Tooling API you can drive build across all Gradle version since 1.0.
Querying for Project model
You can query Gradle for the details of a build, including the project hierarchy and the project dependencies, external dependencies (including source and Javadoc jars), source directories and tasks of each project.
Query for Build environment information
Gradle provides programmatically access to information about the build environment. This includes information about the Gradle Version, The Gradle User Home directory and the Java Home directory.
Execute a build
You can execute a build and listen to stdout and stderr logging and progress (e.g. the stuff shown in the 'status bar' when you run on the command line).
Build Operation Cancellation
All operations initiated via the Gradle Tooling API are gracefully cancellable at any time during the build
Support custom JVM settings
JVM args provided via the Gradle Tooling API take precedence over gradle.properties
Provide Eclipse Project Model
The Gradle Tooling API provides a model of how your project is mapped to an Eclipse project.
Provide IDEA Project Model
The Gradle Tooling API provides a model how to your project is mapped to the IDEA model.
Provide support for custom Project Model
Gradle Run Task
You can write a Gradle plugin to add custom metadata for the Gradle Tooling API. You can use this for example when you integrate your own product/customizations with Gradle.
Run specific tests
The TestLauncher API allows running specific JUnit or TestNG Tests within one or more Test Tasks
Register for progress events
Register for events of task or test progress to get informed about the process of the build with rich information about the processed task and test
Run Continuous Builds
Gradle Tooling API provides the functionality to run a build programmatically in 'continuous build' mode. Changes on build inputs (File changes) continuously trigger specified tasks to run.
Gradle Parallel Task Execution Software
Customizable Logging
Custom Logging Schemas
You can replace much of Gradle’s logging UI with your own. You might do this, for example, if you want to customize the UI in some way, e.g. to log more or less information, or to change the formatting.
Redirecting Output from Other Tools
The build output is very important for the build user experience. If you integrate with external tools and libraries their console output might be very verbose. In Gradle System.out and log output of Java Util Logging, Jakarta Commons Logging and Log4j is re-reouted to the Gradle logging system. You can define per external tool you are integrating with to which log level the output should be routed.
Optimizing the build-edit-build loop
In the past, we’ve recommended that you enable the Gradle Daemon (and parallel execution, with some caveats) to get the best performance out of Gradle. We’ve also talked about using incremental builds to speed up your build-edit-build feedback loop by skipping unnecessary work. Now there’s another optimization available—one that allows you to get out of the way and let Gradle start the build for you.
As of 2.5, Gradle supports continuous build execution, which will automatically re-execute builds when changes are detected to its inputs. There have been a few community plugins that add support for a Gradle “watch” mode that do something similar.
With Maven, the same watch functionality needs to be implemented for each plugin or you have to use a plugin that has a predefined set of goals. Ikaika kang nationality meaning. We wanted to do better than that. We wanted any plugin to be able to leverage the power of continuous builds without having to supply additional information. We also wanted the set of tasks to execute to be completely ad-hoc. Since Gradle needs to know a task’s inputs and outputs for incremental builds, we had all the information necessary to start watching for changes.
Using continuous build
Continuous build can be used with any task or set of tasks that have defined inputs and outputs. If you’re using well-behaved tasks, this shouldn’t be a problem for most builds. If you find that your build isn’t rebuilding with continuous build as you think it should, it could point to a problem in your build script.
Command-line option
You enable continuous build with the
-t
or --continuous
command-line option along with whichever tasks you want to run (we call these task selectors). At least one task that runs needs to define inputs to enter continuous build mode.For example, on a typical Java project,
Gradle Exec Task
would enable continuous build and re-run tests any time the main sources or test sources change.
We’re not limited to a single task, so we could also re-run tests and FindBugs on the main sources using
Gradle Parallel Task Execution Definition
Determining when to run another build
When you run Gradle with the continuous build option, Gradle executes the build as usual, except Gradle also registers the inputs to all tasks with a file watch service. Even tasks that are
UP-TO-DATE
will have their inputs recorded, so all inputs can be considered when triggering a new build. This means that you don’t have to start from a clean build for Gradle to know which inputs could change in continuous build mode.After the end of the build, Gradle will start watching for file system changes based on the collected inputs. The Gradle command-line interface will display the message
Waiting for changes to input files of tasks
on the console and will wait for changes to inputs. If any of the input files are changed or deleted, Gradle will execute another build with the identical set of task selectors. Gradle can detect changes to simple files (deleted, modified) and changes to directories (deleted or new files).See a demo of this in action:
Exiting continuous build
Once Gradle is running in continuous build, it will not exit, even if the build is not successful. To get out of continuous build, you should use
Ctrl-D
to cancel the build. On Microsoft Windows, you must also press ENTER
or RETURN
after Ctrl-D
.If you use
Ctrl-C
, Gradle will exit abruptly and also kill the Gradle Daemon.UPDATE: As of Gradle 3.1,
Ctrl-C
no longer kills the Gradle Daemon.Limitations
The User Guide chapter describes all limitations and quirks with continuous build.
Requires Java 7 or better
Gradle uses Java 7’s WatchService to watch for changes to inputs. This functionality is only available on JDK 7 or later.
Mac OS X performance
For GNU/Linux and Microsoft Windows, the file system change events are provided through a kernel service. For Mac OS X, Java falls back to a polling-based system. This means on Mac OS X only, change detection on a very, very large number of input files may be delayed and, in some cases, cause a deadlock. Both of these issues are tracked as JDK bugs: JDK-7133447 and JDK-8079620.
Changes to build scripts
Gradle doesn’t consider changes to your build logic when in continuous build mode. Build logic is created from
build.gradle
, settings.gradle
, gradle.properties
and other sources. If you make changes to your build scripts, you’ll have to exit continuous build and restart Gradle. Future versions of Gradle will make it easier to describe inputs to your build logic so that continuous build can work with this as well.Future improvements
In addition to mitigating some of the limitations with the current implementation, there are other interesting things we can use continuous build to accomplish.
Right now, there are not any supported, public ways of managing a process started by Gradle that needs to exist between builds. Gradle expects that a process started (e.g., via
Exec
) will exit as part of the build.In the next release (2.6), Play support is coming to Gradle, and with that you’ll be able to start Play applications in a separate JVM for local development. With continuous build enabled, Gradle will hot-reload the Play application whenever classes or assets are changed. The Play plugin accomplishes this by registering the Play JVM with Gradle in a way that survives between builds.
We want to eventually evolve this Play specific reload functionality into a general feature, so plugins can have their own “hot-reload”-like behavior.
Another opportunity for improvement is up-to-date checking. For very large projects, up-to-date checking can be time consuming for the no-op case. When looking for out-of-date files, Gradle must scan entire directories or recalculate file checksums. When using continuous build, Gradle must already keep track of file and directory changes, so in some cases, Gradle may be able to skip checks for files that are known to have not changed.
Feedback
Please let us know on the forums if you run into any surprises with this new feature.
Related Posts
- ❯ Introducing Java toolchains
- ❯ Introducing Configuration Caching
- ❯ Introducing file system watching