Knowledge Base > DCover CLI > Building a Maven Project

Building a Maven project

Single module project

If your project uses the Maven build system, cd into the directory containing the pom.xml file. This is typically located at the root of your repository.

To compile the project, run the mvn install command. If successful, you should see a BUILD SUCCESS message towards the end of the output from Maven. Note that we recommend mvn install rather than mvn compile because the former may produce configuration files which have to be taken into account to verify the tests.

Multi module project

If your project uses the Maven build system, cd into the root directory of the project you wish to build. Diffblue Cover must be run for each module separately but the project must be compiled at the project root level.

To compile the project, run the mvn install command. If successful, you should see a BUILD SUCCESS message towards the end of the output from Maven. Note that we recommend mvn install rather than mvn compile because the former may be required to resolve dependencies correctly which have to be taken into account to verify the tests.

Now cd into the directory containing the pom.xml file for the module you wish to generate tests for.

Maven 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.

If you have supplied these system properties to dcover:

dcover create -Dproperty1=value1

Then you must also supply those same system properties to Maven when executing your tests, either as command line options:

mvn test -Dproperty1=value1

Or in the <environmentVariables> section of your Surefire plugin configuration:

<plugin>
  <artifactId>maven-surefire-plugin</artifactId>
  <configuration>
  <systemPropertyVariables>
    <property1>value1</property1>
  </systemPropertyVariables>
  </configuration>
</plugin>

Maven Troubleshooting

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

If your project uses the Checkstyle plugin (https://maven.apache.org/plugins/maven-checkstyle-plugin/) please either:

  • Allow the tests to be verified using the command --ignore-stylecheck=true
  • Amend the pom file to exclude Diffblue tests, as shown in the example below.
<plugin>
   <groupId>org.apache.maven.plugins</groupId>
   <artifactId>maven-checkstyle-plugin</artifactId>
      <configuration>
         <excludes>**/generated/**/*</excludes>
      </configuration>
</plugin>