Knowledge Base > Cover CLI > Building a Maven Project
Building a Maven project
- Single module project
- Multi module project
- Maven and user-specified system properties
- Maven Troubleshooting
- The -g option
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
Checkstyle Plugin
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>
JUnit Platform Launcher jar
dcover
detects and utilizes the JUnit Platform Launcher jar used by your Maven Surefire
plugin. There is no need to include the junit-platform-launcher
jar as a test dependency.
Including an incompatible launcher dependency may even cause execution of your mvn test
phase to fail. The snippet below captures the output of such a failure:
[ERROR] There was an error in the forked process
[ERROR] java.lang.NoClassDefFoundError: org/junit/platform/commons/util/ClassNamePatternFilterUtils
[ERROR] org.apache.maven.surefire.booter.SurefireBooterForkException: There was an error in the forked process
The -g option
The -g option (which is on in Maven, by default) is needed for Diffblue Cover to write the best tests possible. If you have switched off the -g option, please switch it back on again.
For Maven documentation, please see: http://maven.apache.org/plugins/maven-compiler-plugin/compile-mojo.html#debuglevel