Create
cancel
Showing results for 
Search instead for 
Did you mean: 
Sign up Log in

How do I get clover to use instrumented jar files in a war file

Sigurd Knippenberg January 24, 2013

I have a Maven 3 project that has multiple modules. 4 modules generate jar files and then one module creates a war file that includes all the jar files (this war module includes no code but does include integration test cases and starts Tomcat using cargo).

I have clover configured like this in the root pom.xml file:

under build:

<plugin>

<groupid>com.atlassian.maven.plugins</groupid>

<artifactid>maven-clover2-plugin</artifactid>

<version>3.1.10</version>

<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>

under reporting:

<plugin>

<groupid>com.atlassian.maven.plugins</groupid>

<artifactid>maven-clover2-plugin</artifactid>

<version>3.1.10</version>

<configuration>

</configuration>

</plugin>

When I run the build with mvn clean clover2:setup install clover2:aggregate clover2:clover I get no code coverage for my integration tests. I see that clover generates -clover jar files for each of my jar modules, but when I look at the war file in the target/clover directory of my war module it doesn't include the -clover jar files but the regular jar files. I assume that to get code coverage to work for my integration test cases that the war file needs to contain the -clover jar files. I didn't look just at the jar file names, I also looked inside the jar files to verify whether they contained the instrumented class files or not. They did not.

How do I get clover to use the -clover jar files in the war file?

Thanks.

1 answer

1 accepted

0 votes
Answer accepted
Marek Parfianowicz
Atlassian Team
Atlassian Team members are employees working across the company in a wide variety of roles.
February 5, 2013

Hello Sigurd,

1) Please do not use clover2:setup together with clover2:instrument. Both goals do exactly the same (instrument files), but the clover2:instrument performs this in a forked build life cycle (that's why there are *-clover.jar files produced) while the clover2:setup performs it in the default life cycle (so that jar files keeps their original name).

2) Please do not define <goal>aggregate</goal> target in the pom for multi-module Maven projects. Due to a bug in @aggregator implementation in Maven, such goal might not be executed as the last one. Instead of this, call clover2:aggregate from command line.

3) If you have doubts whether your war/jar file contains instrumented code, please check if you can find files named like 'MyClass$__CLR3_1_7bbh54znlh7.class' inside the jar.

I recommend the following:

A. don't define Clover goals in the pom.xml, just configuration, e.g.:

&lt;plugin&gt;
  &lt;groupId&gt;com.atlassian.maven.plugins&lt;/groupId&gt;
  &lt;artifactId&gt;maven-clover2-plugin&lt;/artifactId&gt;
  &lt;version&gt;3.1.10&lt;/version&gt;
  &lt;configuration&gt;
    &lt;!-- put configuration here, if needed --&gt;
  &lt;/configuration&gt;
&lt;/plugin&gt;

2. use clover2:setup instead of clover2:instrument, call Clover goals from command line, e.g.:

mvn clean clover2:setup install clover2:aggregate clover2:clover

One more tip:

As you're creating a WAR file I assume you will deploy it to a web server. In such case please make sure that clover.jar (com.cenqua.clover:clover) is available in server's class path. Usually it requires either:

  • copying clover.jar to <server>/lib directory (for tests performed outside the build for instance) or
  • adding proper com.cenqua.clover:clover dependency in pom.xml (in case of in-container tests running from Maven build for instance)


You will also have to ensure that clover.db is available at runtime. The best would be to define an absolute path to clover.db and use a single database (as you have multi-module project I guess). For example:

&lt;plugin&gt;
&lt;groupId&gt;com.atlassian.maven.plugins&lt;/groupId&gt;
&lt;artifactId&gt;maven-clover2-plugin&lt;/artifactId&gt;
&lt;version&gt;3.1.10&lt;/version&gt;
&lt;configuration&gt;
  &lt;singleCloverDatabase&gt;true&lt;/singleCloverDatabase&gt;
  &lt;cloverDatabase&gt;/absolute/path/to/clover.db&lt;/cloverDatabase&gt;
&lt;/configuration&gt;
&lt;/plugin&gt;

See also:


Regards
Marek

Suggest an answer

Log in or Sign up to answer
TAGS
AUG Leaders

Atlassian Community Events