Knowledge Base > DCover CLI > Building a Gradle project

Building a Gradle project

If your project uses the Gradle build system, cd into the directory containing the build.gradle file for the module you wish to build.

For a single-module project, this is typically located at the root of your repository. For a multi-module project, this may be within a sub-directory.

To compile the project, if a gradlew (or gradlew.bat on Windows) file is present, run the ./gradlew build command, otherwise run gradle build.

It is generally preferable to execute Gradle commands using ./gradlew (or gradlew.bat on Windows) rather than gradle if these Gradle wrapper scripts are present in your project.

In either case, if successful, you should see a BUILD SUCCESSFUL message towards the end of the output from Gradle:

7 actionable tasks: 2 executed, 5 up-to-date

In order to run Diffblue Cover CLI it is essential that your Gradle project builds successfully. If it finds a Gradle project, DCover will call Gradle to determine your project settings. If your Gradle project fails then DCover will exit with an error message (and reason):

ERROR An error was encountered while building the Gradle project at ...

If there is a Gradle wrapper for your project (gradlew, gradlew.bat), DCover will use the wrapper’s declared version in preference to your system’s installed Gradle version.

Gradle and user-specified system properties

The -D or --define option allows the user to pass additional system properties to dcover for test creation and execution.

Any created tests may depend upon these user-specified system properties and may not execute successfully without them.

Unfortunately by default Gradle does not forward command line system properties to test execution. Therefore out-of-the-box dcover may fail to validate your tests.

You can overcome this issue with additional configuration. If you have supplied these system properties to dcover:

dcover create -Dproperty1=value1 -Dproperty2=value2

Then you must also supply those same system properties to Gradle test execution before running dcover create.

Specify your system properties in the test task:

test {
  systemProperty 'property1', 'value1'
  systemProperty 'property2', 'value2'

Keeping these properties in sync will ensure that test validation will succeed and that your created tests can be executed successfully from Gradle.

Gradle Troubleshooting

If dcover cannot verify the tests it creates due to an incompatibility with the stylecheck used in your environment, you will receive an error message.

If your project uses the Gradle Checkstyle plugin (, amend the build.gradle file to exclude Diffblue tests, as shown in the example below:

tasks.withType(Checkstyle) {
    exclude '**/*DiffblueTest**'