How to integrate Clover in my Maven 3 builds?

I am trying to add Clover to my existing multi-module project but I'm failing miserably. I sure could use some help.

At this moment there are already JUnit tests in the projects and Checkstyle, FindBugs and PMD are bound to the 'verify' phase.

I run my builds with just 'mvn clean install' and everything gets done: testing, packaging, CS, FB, PMD.

In my root POM I have added following:

<build>
<pluginManagement>
<plugins>
<plugin>
<groupId>com.atlassian.maven.plugins</groupId>
<artifactId>maven-clover2-plugin</artifactId>
<version>3.1.0</version>
<dependencies>
<dependency>
<groupId>com.jnj.gtsc.framework6</groupId>
<artifactId>framework6-buildtools</artifactId>
<version>${fw6.version}</version>
</dependency>
</dependencies>
<configuration>
<licenseLocation>config/java/clover.lic</licenseLocation>
<targetPercentage>50%</targetPercentage>
</configuration>
<executions>
<execution>
<phase>verify</phase>
<goals>
<goal>setup</goal>
<goal>check</goal>
<goal>clover</goal>
</goals>
</execution>
</executions>
</plugin>

In one of the modules I have added this:
<build>
<plugins>
<plugin>
<groupId>com.atlassian.maven.plugins</groupId>
<artifactId>maven-clover2-plugin</artifactId>
</plugin>

When I run 'mvn clean install, the build fails with following error:

[INFO] --- maven-clover2-plugin:3.1.0:setup (default) @ filebrowser-services ---
[INFO] Clover Version 3.1.0, built on May 31 2011 (build-821)
[INFO] Loaded from: c:\repo\com\cenqua\clover\clover\3.1.0\clover-3.1.0.jar
[INFO] Clover: Commercial License registered to Janssen Pharmaceutica NV Beerse.
[INFO] Creating new database at 'C:\dvl\java\gtsc\services\filebrowser\filebrowser-services\target\clover\clover.db'.
[INFO] Processing files at 1.6 source level.
[INFO] Clover all over. Instrumented 23 files (5 packages).
[INFO] Elapsed time = 0.413 secs. (55.69 files/sec, 5,193.705 srclines/sec)
[INFO] Clover Version 3.1.0, built on May 31 2011 (build-821)
[INFO] Loaded from: c:\repo\com\cenqua\clover\clover\3.1.0\clover-3.1.0.jar
[INFO] Clover: Commercial License registered to Janssen Pharmaceutica NV Beerse.
[INFO] Updating existing database at 'C:\dvl\java\gtsc\services\filebrowser\filebrowser-services\target\clover\clover.db'.
[INFO] Processing files at 1.6 source level.
[INFO] Clover all over. Instrumented 16 files (6 packages).
[INFO] 67 test methods detected.
[INFO] Elapsed time = 0.264 secs. (60.606 files/sec, 8,071.97 srclines/sec)
[WARNING] Using [com.jnj.gtsc.services.filebrowser:filebrowser-config:jar:1.0.0-SNAPSHOT], built on Wed Jun 29 17:43:47 CEST 2011 even though a Clover
ed version exists but it's older (lastModified: Wed Jun 29 16:21:50 CEST 2011 ) and could fail the build. Please consider running Clover again on that
dependency's project.
[INFO]
[INFO] --- maven-clover2-plugin:3.1.0:check (default) @ filebrowser-services ---
[INFO] Checking for coverage of [50%] for database [C:\dvl\java\gtsc\services\filebrowser\filebrowser-services\target/clover/clover.db]
[INFO] Clover Version 3.1.0, built on May 31 2011 (build-821)
[INFO] Loaded from: c:\repo\com\cenqua\clover\clover\3.1.0\clover-3.1.0.jar
[INFO] Clover: Commercial License registered to Janssen Pharmaceutica NV Beerse.
[INFO] Coverage check FAILED
[ERROR] The following coverage targets for null were not met:
Total coverage of 0% did not meet target of 50%
[ERROR] Total coverage of 0% did not meet target of 50%

Whst am I doing wrong?

2 answers

1 accepted

Got it working! Running `mvn clean install` does it all.

<execution>
<phase>verify</phase>
<goals>
<goal>instrument-test</goal>
<goal>check</goal>
</goals>
</execution>

Using `instrument-test` prevents CS, PMD, CPD and FB being run on the instrumented code. The only drawback is that it will run the tests twice.

What is the result if you run the clover command from the commandline instead if binded to an maven lifecycle?

mvn clover2:setup test clover2:aggregate clover2:clover

My first feeling is that the phases a not run in the correct order. You first have to instrument your code (generate-sources phase) then run your unittests and then aggregate and create the report.

Suggest an answer

Log in or Sign up to answer
How to earn badges on the Atlassian Community

How to earn badges on the Atlassian Community

Badges are a great way to show off community activity, whether you’re a newbie or a Champion.

Learn more
Community showcase
Published Monday in Jira Software

How large do you think Jira Software can grow?

Hi Atlassian Community! My name is Shana, and I’m on the Jira Software team. One of the many reasons this Community exists is to connect you to others on similar product journeys or with comparabl...

393 views 5 10
Read article

Atlassian User Groups

Connect with like-minded Atlassian users at free events near you!

Find a group

Connect with like-minded Atlassian users at free events near you!

Find my local user group

Unfortunately there are no AUG chapters near you at the moment.

Start an AUG

You're one step closer to meeting fellow Atlassian users at your local meet up. Learn more about AUGs

Groups near you