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>
The quickest and easiest way to try Clover is from the command line, for example:
mvn clean clover2:setup test clover2:aggregate clover2:clover
Install Clover-for-Maven 2 and 3 by adding it to your Maven build file (pom.xml):
Set up your pom.xml by adding:
<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>
Either change ${clover.version
} to the current Clover version, or define a property in your pom.xml that sets this value.
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.
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.
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> ...
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.