Gradle 2.5 Does Continuous Builds

Gradle 2.5 has been announced this month including a number of incubating features, such as Continuous Builds, Dependency Substitution Rules, Progress Events, Google Tests, and others.

Continuous Builds

One of the most interesting features introduced in Gradle 2.5 is support for continuous builds. When started with the switch –continuous or –t, Gradle will perform the build then watch for changes of the main source code or tests and automatically initiate the same build when a change occurs. If the project’s source code changes, Gradle will recompile it and execute the tests. If the source of the tests changes, then it will recompile the tests and execute them. Only the affected tasks are executed. Changes of build scripts do not initiate another automatic build. A manual build command needs to be issued for those changes to be considered. In the future, the team intends to include remote repositories in the continuous build process.

There are some limitations: changes to the files read during the configuration phase of the build do not trigger a new build. Also, Gradle uses WatchService to monitor for file system changes, which means it requires JDK 1.7 or later to run. On Mac OS X, Gradle relies on OS’s file system polling mechanism which is considered inefficient and can cause deadlock when many files are watched. Creating files in the target directory of a symbolic link, creating/removing symbolic links to directories or modifying/deleting the target of a symbolic link will not trigger a new build.

Dependency Substitution Rules

Dependency substitution rules allow replacing a dependency on a project with an external module, as shown in the following snippet taken from the user guide:

This is helpful to speed up a multi-project build, enabling downloading some dependencies from external repositories rather then building them.

Substitutions can be defined the other way around, replacing an external module with a local project. This could be useful when attempting to build with a local version of a dependency for testing purposes. The substitution can specify the version of the module or not:

TheaddProgressListener(ProgressListener) method can be used to register listeners to various build events triggered when the task graphs is constructed, when task execution is started/stopped, or when test execution is started/stopped.

Google Tests

Gradle now has a plug-in providing rudimentary support for the compilation and execution of Google Tests. Plans for the future include better HTML reporting, real-time feedback on test execution and support for other testing frameworks.

Other

Other new features in Gradle 2.5 are: simpler default dependencies, precompiled header support, and improvements of the managed model. A number of features have been deprecated, and a number of issues have been fixed. There is also a number of potential breaking changes.