This is the documentation for Clover 3.3. View this page for the

Unknown macro: {spacejump}

of Clover, or visit the latest Clover documentation.

Configuring Clover's short name in .m2/settings.xml

Before you get started, add this to your .m2/settings.xml file so you can reference Clover by its short name clover2.

<pluginGroups>
    <pluginGroup>com.atlassian.maven.plugins</pluginGroup>
</pluginGroups>

 

Running Clover goals from the command line

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

mvn clean clover2:setup test clover2:aggregate clover2:clover

 

Installing Clover in pom.xml

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

  1. Set up your pom.xml by adding:

    pom.xml
    <build>
        <plugins>
            ...
            <plugin>
                <groupId>com.atlassian.maven.plugins</groupId>
                <artifactId>maven-clover2-plugin</artifactId>
                <version>${clover.version}</version>
                <configuration>
                    <licenseLocation>/path/to/clover.license</licenseLocation>
                </configuration>
            </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.

    mvn clean clover2:setup test clover2:aggregate clover2:clover

    This will instrument your sources, build your project, run your tests and create a Clover coverage report in the target/site/clover directory.

    You can also have Clover run as part of your build by adding Clover's goals in pom.xml.

 

There are four 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:aggregate goal is used for merging coverage data generated by multi-module projects.
  4. The clover2:clover goal generates an HTML, XML, PDF or JSON report.

Running Goals via pom.xml

The goals described above can be executed by specifying them in your pom.xml.

To generate a Clover report when you run the site goal:

<project>
  ...
  <reporting>
    <plugins>
      ...
      <plugin>
        <groupId>com.atlassian.maven.plugins</groupId>
        <artifactId>maven-clover2-plugin</artifactId>
        <configuration>
          ...
        </configuration>
      </plugin>
    </plugins>
  </reporting>
...

To instrument your sources whenever you build:

<project>
  ...
  <build>
    <plugins>
      <plugin>
        <groupId>com.atlassian.maven.plugins</groupId>
        <artifactId>maven-clover2-plugin</artifactId>
        <configuration>
          ...
        </configuration>
        <executions>
          <execution>
            <phase>generate-sources</phase>
            <goals>
              <goal>instrument</goal>
            </goals>
          </execution>
        </executions>
      </plugin>
    </plugins>
  </build>

To include aggregation of child modules:

<project>
...
  <build>
        <plugins>
            <plugin>
                ...
                <executions>
                    <execution>
                        <id>main</id>
                        <phase>verify</phase>
                        <goals>
                            <goal>instrument</goal>
                            <goal>aggregate</goal>
                        </goals>
                    </execution>
                    <execution>
                        <id>site</id>
                        <phase>pre-site</phase>
                        <goals>
                            <goal>instrument</goal>
                            <goal>aggregate</goal>
                        </goals>
                    </execution>
                </executions>
            </plugin>
        </plugins>
    </build>
...

 

Using clover2:setup and clover:instrument

The Clover 'instrument' goal (clover2:instrument) can be used if you need to actually deploy a project's artifact to production and have Clover run at the same time. This will fork the lifecycle and cause each Clover artifact to contain the -clover classifier. It means that the build is performed twice.

The Clover 'setup' goal (clover2:setup) will perform instrumentation in the main build life cycle, therefore it's not recommended to use it together with 'install' or 'deploy' goals. The benefit of this approach is that build is made only once.

  • No labels