This documentation is for Clover 4.0.x. Earlier versions are available here.

Versions Compared

Key

  • This line was added.
  • This line was removed.
  • Formatting was changed.

...

Maven Site Docs
For documentation presented in the standard Maven format, see the Maven Site Docs.

On this page:

Table of Contents

Basic Usage

The quickest and easiest way to try Clover is from the command line, for example:

Code Block
mvn clover2:setup test clover2:aggregate clover2:clover
Excerpt

Install Clover-for-Maven 2 and 3 by adding it to your Maven 2 and 3 build file (pom.xml):

  1. Set up your pom.xmlby adding:

    Code Block
    xml
    titlepom.xml
    xml

...

  1. <build>
        <plugins>
            ...
            <plugin>
                <groupId>com.atlassian.maven.plugins</groupId>
                <artifactId>maven-clover2-plugin</artifactId>
                <version>${clover.version}</version>
            </plugin>
            ...
        </plugins>
    </build>
    

    (info) Either change ${clover.version} to the current Clover version, or define a property in your pom.xml that sets this value.

    (warning) Clover ships with a 30 day evaluation license. After 30 days you need a valid Clover license file to run Clover. You can obtain a free 30 day evaluation license or purchase a commercial license at http://my.atlassian.com. You will need to set up your licence, as a <licenseLocation> element in your pom.xml configuration file.

  2. Now, simply invoke Clover with Maven on the command line. This will instrument your sources, build your project, run your tests and create a Clover coverage database.

You can also have Clover run as part of your build. Learn how.

There are three basic parts executed when recording code coverage with Clover.

  1. The clover2:setup goal will instrument your Java source files.
  2. The test phase is Maven 2 and 3's standard command for running a unit test phase.
  3. The clover2:clover goal generates an HTML, XML, PDF or JSON report.

(info) The command clover2:aggregate goal is used for merging coverage data generated by multi-module projects.

Hence, if you use the following code:

Code Block
mvn clover2:setup test clover2:aggregate clover2:clover

This will create a coverage report, which will be created in this directory:

Code Block
target/site/clover

Clover should now be fully set up for basic operation.

For more license configuration options, see the FAQ pages.

Checking a Coverage Goal

You can check that your test coverage has reached a certain threshold, and fail the build if it has not by adding a targetPercentage tag to your plugin configuration in pom.xml:

...

(warning) If you omit this version element, the GMaven Plugin will default to using Groovy version 1.6.0, which is not compatible with Clover.

Code Block
xml
xml

...
  <plugins>
    ...
      <plugin>

          <groupId>org.codehaus.groovy.maven</groupId>
          <artifactId>gmaven-plugin</artifactId>
          <version>1.0-rc-5</version>

          <dependencies>
              <dependency>
                  <groupId>org.codehaus.groovy</groupId>
                  <artifactId>groovy-all</artifactId>
                  <version>1.6.2</version>
              </dependency>
          </dependencies>

          <executions>
              <execution>
                  <goals>
                      <goal>generateStubs</goal>
                      <goal>compile</goal>
                      <goal>generateTestStubs</goal>
                      <goal>testCompile</goal>
                  </goals>
              </execution>
          </executions>

      </plugin>
    ...
  </plugins>
...

...

To do so, set up your .m2/settings.xml by adding:

Code Block
xml
title.m2/settings.xml
xml
...
<pluginGroups>
    <pluginGroup>com.atlassian.maven.plugins</pluginGroup>
</pluginGroups>
...

...