Gradle introduced the continuous build feature in version 2.5. The feature is still incubating, but we can already use it in our daily development. The continuous build feature means Gradle will not shut down after a task is finished, but keeps running and looks for changes to files to re-run tasks automatically. It applies perfectly for a scenario where we want to re-run the test
task while we write our code. With the continuous build feature we start Gradle once with the test
task and Gradle will automatically recompile source files and run tests if a source file changes.
To use the continuous build feature we must use the command line option --continuous
or the shorter version -t
. With this option Gradle will start up in continuous mode. To stop Gradle we must use the Ctrl+D key combination.
In the following output we see how to start Gradle in continuous mode and run the test
tasks. The first time our test code fails, we change the source file and without restarting Gradle the file is compiled and the test
task is run again. Notice that Gradle will honour the task dependencies to see if files have changed:
$ gradle -t test Continuous build is an incubating feature. :compileJava UP-TO-DATE :compileGroovy :processResources UP-TO-DATE :classes :compileTestJava UP-TO-DATE :compileTestGroovy :processTestResources UP-TO-DATE :testClasses :test com.mrhaki.SampleSpec > get message FAILED org.spockframework.runtime.SpockComparisonFailure at SampleSpec.groovy:7 1 test completed, 1 failed :test FAILED FAILURE: Build failed with an exception. * What went wrong: Execution failed for task ':test'. > There were failing tests. See the report at: file:///Users/mrhaki/.../build/reports/tests/index.html * Try: Run with --stacktrace option to get the stack trace. Run with --info or --debug option to get more log output. BUILD FAILED Total time: 4.464 secs Waiting for changes to input files of tasks... (ctrl-d to exit) Change detected, executing build... :compileJava UP-TO-DATE :compileGroovy UP-TO-DATE :processResources UP-TO-DATE :classes UP-TO-DATE :compileTestJava UP-TO-DATE :compileTestGroovy :processTestResources UP-TO-DATE :testClasses :test BUILD SUCCESSFUL Total time: 1.792 secs Waiting for changes to input files of tasks... (ctrl-d to exit)
Written with Gradle 2.6.