Home | Forums

Quick Start Guide for Ant

This section shows you how to quickly get Clover integrated into your build. Clover instrumentation and reporting are highly configurable so later sections of this manual will detail available configuration options and typical usage scenarios.

Follow these simple steps to integrate Clover with your build:

Install Clover

ensure you are using a recent version of Ant (v1.4.1 or greater)

copy <CLOVER_HOME>/lib/clover.jar into <ANT_HOME>/lib. (If you can't install into ANT_HOME/lib, see Installation Options).

Add Clover targets

Edit build.xml for your project:

  1. add the Clover Ant tasks to your project:
     <taskdef resource="clovertasks"/>
  2. add a target to switch on Clover:
     <target name="with.clover">
        <clover-setup initString="mycoverage.db"/>
  3. add one or more targets to run clover reports:

    to launch the Swing viewer, use:

     <target name="clover.swing" depends="with.clover">
    - OR - for html reporting, use (change the outfile to a directory path where Clover should put the generated html):

    - OR - for xml reporting, use (change the outfile to a file where Clover should write the xml file):

     <target name="clover.xml" depends="with.clover">
           <current outfile="coverage.xml">
              <format type="xml"/>
    - OR - for pdf reporting, use (change the outfile to a file where Clover should write the pdf file):

     <target name="clover.pdf" depends="with.clover">
           <current outfile="coverage.pdf">
              <format type="pdf"/>
    - OR - for simple emacs-style reporting to the console, try:

     <target name="clover.log" depends="with.clover">
  4. Add clover.jar to the runtime classpath for your tests. How you do this depends on how you run your tests. For tests executed via the <junit> task, add a classpath element:

     <junit ...>
             <pathelement path="${ant.home}/lib/clover.jar"/>

Compile and run with Clover

Now you can build your project with Clover turned on by adding the "with.clover" target to the list of targets to execute. For example (if your compile target is named 'build' and your unit test target is named 'test'):

 ant with.clover build test

Generate a Coverage Report

To generate a Clover coverage report: