This section describes some recommended practices when integrating Clover into your Ant build. For a great list of general Ant best practices, see http://www.onjava.com/pub/a/onjava/2003/12/17/ant_bestpractices.html.
Let Clover automatically choose the database location
The initstring
attribute is optional. If not supplied, Clover will automatically create a special directory for the Clover coverage database. There are several advantages in letting Clover use the default location. Clover tasks can find the database more easily, and build files become more portable. If left to the default setting, there is no need to have Clover reporting targets depend on the the Clover setup target.
注意
If you want to specify the initstring
explicity, it is strongly recommended that you give Clover its own direct directory, because a Coverage run can result in many files being written to the database.
<clover-clean>
task<clover-clean>
to delete the database so that it will be freshly created for the next build. This is easily achieved by adding the <clover-clean>
task to any existing clean target.<javac>
task<javac>
taskUse Target dependencies in preference to <ant>
and <antcall>
Ant's target dependencies are an efficient way to manage build dependencies. You should always strive to use this mechanism over the more 'procedural' style of explicitly calling targets. By explicitly calling Ant tasks, you miss out on Ant's powerful dependency management where up-to-date targets are skipped. You also introduce significant memory overhead (particularly if fork="true"
is set). Excessive use of <antcall>
can also make a build file less readable, because it can be difficult to trace which properties and references are valid for a given target.
If you must use <ant>
and <antcall>
, be aware that you must set inheritrefs
to "true" if you are calling <clover-setup>
in an upper-level project.
Below, we demonstrate an alternative. Instead of this:
<!-- BAD. References wont be passed (References from <clover-setup/> would be lost). --> <target name="all"> <antcall target="clean"> <antcall target="compile"> <antcall target="dist"> <antcall target="test"> </target>
it is much better to use something like this:
<!-- GOOD --> <target name="all" depends="clean, compile, dist, test"/>
<junit>
task, consider using fork="true" forkmode="once"