------ Maven 2 Clover Plugin: using ------ Vincent Massol ------ April 1st, 2006 Generating a Clover report when generating the site Add the Clover report in your <<>> under the <<>> section: +-------- [...] [...] org.apache.maven.plugins maven-clover-plugin [...] [...] +--------- The <<>> report will only generate a report out of an existing Clover database so if you don't have a Clover database available you'll need to configure your build to generate one. This is achieved by binding the <<>> goal to the <<>> phase so that it executes before the report executes. For example: +-------- [...] org.apache.maven.plugins maven-clover-plugin [...] pre-site instrument [...] +--------- Then, to generate the report as part of the site simply type <<>>. Generating a Clover report without modifying your POM If you simply want to generate a Clover report on the fly without modifying your POM, simply type <<>>. Alternatively if you want to aggregate children module reports into a master Clover report, run <<>> instead. Generating HTML, XML and PDF reports By default the Clover plugin will generate a HTML report. If you want to generate a PDF or XML report, or if you simply do not want to generate the HTML report use the <<>>, <<>> and <<>> configuration elements. By default the <<>> element is set to true. For example if you wish to generate the PDF and XML reports you would use: +-------- [...] org.apache.maven.plugins maven-clover-plugin true true [...] +--------- Note that only the HTML report gets a link in the "Project Reports" section in generated menu on the site. If you want to link the PDF or XML reports you'll need to do that by modifying your <<>>. For example: +-------- [...] [...] +--------- If you do not want to generate the HTML report then you should not configure the Clover plugin in the <<>> section as this section is for plugins which generate HTML reports. In that case, simply bind the <<>> goal to the <<>> phase in the <<>> section. For example: +-------- [...] org.apache.maven.plugins maven-clover-plugin false true true site instrument clover [...] +--------- Generating historical reports This is done in the same manner as you generate a standard Clover report but in addition you need to set the <<>> configuration property to true (it's false by default). For example: +-------- [...] org.apache.maven.plugins maven-clover-plugin true [...] [...] [...] +--------- Now this will generate a historical report only if you have saved Clover historical savepoints. In order to save a Clover savepoint, run the <<>> goal. It's up to you to decide when you want to call this goal. For example you could call it every time a build is executing on your CI server, or you could call it at every project release, etc. The location of the history directory for saving the savepoints is controlled by the <<>> configuration property, which points to <<<${project.build.directory}/clover/history>>> by default. It is recommended to use another location that will not get erased by a <<>>. For example: +-------- [...] org.apache.maven.plugins maven-clover-plugin true ${myHistoryDir} [...] [...] [...] +--------- Where <<>> could be a Maven property that you define in a profile. Checking test coverage In order to check for a test coverage percentage and fail the build in case of non-compliance, you'll need to configure the Clover plugin to tell it what test coverage threshold you wish to use: +-------- org.apache.maven.plugins maven-clover-plugin 50% verify instrument check +--------- In this example you've told Maven to run <<>> and <<>> whenever the <<>> phase is reached (this will be the case if you run <<>> for example). You need to call <<>> before the check because <<>> requires an existing Clover datababase to perform the verification. If you don't specify a target percentage the default value used is 70%. You can also invoke <<>> directly on the command line. Note: The <<>> goal will also check the test percentage coverage for merged databases if any is found. Using Clover with JDK 1.4 and JDK 1.5 keywords If your code is using JDK 1.4 or JDK 1.5 specific keywords, you'll need to configure the Clover plugin. For example for JDK 1.4: +-------- org.apache.maven.plugins maven-clover-plugin 1.4 [...] +--------- Specifying a Clover flush policy If you want to specify the Clover {{{http://cenqua.com/clover/doc/adv/flushpolicies.html}flush policy}} that the plugin should use, then specify it in the plugin's configuration. Valid policies are <<>>, <<>> and <<>>. For example to use a <<>> policy with a flush interval of <<<5000>>> ms you would write: +-------- org.apache.maven.plugins maven-clover-plugin threaded 5000 [...] +--------- Specifying a custom license file The Clover plugin provides a default evaulation license. However if your project is a commercial project you need to purchase your own license to use Clover. To use your license specify it using a <<>> configuration element. For example if you wanted to automatically execute the <<>> goal when you type <<>> and if you wanted to use your license located in <<<${basedir}/src/test/clover/myclover.license>>> you would use: +-------- org.apache.maven.plugins maven-clover-plugin ${basedir}/src/test/clover/myclover.license 50% verify instrument check +--------- Important note: The <<>> element needs to be defined in the global <<>> element and not in the <<>> element under the <<>> tag. Instead of specifying a file, you can also specify either a <> or a <> (to learn how to use this last feature, refer to the {{{http://maven.apache.org/plugins/maven-checkstyle-plugin/tips.html}Checkstlye plugin documentation}}. Aggregating Clover reports <> You can aggregate children modules Clover reports into a single master report by running the <<>> goal. For example if you have the following project layout: +-------- myproject/ |_ project1/ |_ pom.xml |_ project2/ |_ pom.xml |_ pom.xml +--------- Then, ensure that your <<>> contains the following: +-------- [...] [...] org.apache.maven.plugins maven-clover-plugin [...] org.apache.maven.plugins maven-clover-plugin pre-site instrument aggregate [...] +--------- When you run <<>> in <<>>, the plugin will instrument your sources, run your tests, aggregate the different Clover databases generated for each build module (i.e. <<>> and <<>>) and generate a master Clover report in the site for the <<>> project. Note that you can control the location of the master Clover database by using the <<>> configuration property. Controlling files to instrument By default all Java files are included during the instrumentation. To specify inclusion and exclusion use the <<>> and <<>> configuration elements as shown in this example: +-------- org.apache.maven.plugins maven-clover-plugin **/api/**/*.java some/path/MyFile.java [...] **/*Test/java [...] [...] +---------