Gradle and Cucumber-JVM

Gradle is a great build tool. Cucumber-JVM
is a great tool for executing Gherkin. They don't really work
well together. At least not out of the box. Gradle defaults to hide the output on stdout and stderr. This is very
unfortunate since this means that the code snippets Cucumber-JVM suggests when there is a missing step are hidden.

Let me show you an example on how to setup a Gradle project so it can execute Cucumber-JVM and give you the snippets
you want as starting points for your steps.

I assume that you have Gradle installed. If not, now is a good time to install it.

With Gradle installed, all we need is a project to work with. The easiest way to get started is to clone the getting started project available on GitHub.

This Gradle project will be used to build a Java project. This means that we have to apply the Java plugin.

We also need some dependencies. Especially the dependency to Cucumber and JUnit.

The dependencies need to be fetched from somewhere. Gradle doesn't have a default repository so I specify Maven central.

Then it is time for the magic: Two extensions to the test task that will allow us to

see stuff Cucumber prints

send command line parameters to the JVM running the tests

Gradles default behaviour is to hide stdout and stderr. By specifying testLogging.showStandardStreams =
true I am able to replace that behaviour with a behaviour that is friendlier to Cucumber users.

I want to be able to send command line arguments to the JVM that will execute the tests. Specifying a
-D property when running Gradle will only forward that property to the JVM that executes Gradle. This
is probably a good behaviour in some cases, but I want to be able to send arguments to Cucumber from the command
line. The way to do this is to extend the test task with systemProperties System.getProperties()

Missing snippets

Gradle tries to optimise its execution. If it can't detect any changes, Gradle will view the task as up to date.
This means that there are cases when you won't get the expected output shown above. The way to force Gradle to run
tasks that are up to date is to specify the command line argument --rerun-tasks.