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:
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?
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.:
<plugin> <groupId>com.atlassian.maven.plugins</groupId> <artifactId>maven-clover2-plugin</artifactId> <version>3.1.10</version> <configuration> <!-- put configuration here, if needed --> </configuration> </plugin>
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:
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:
<plugin> <groupId>com.atlassian.maven.plugins</groupId> <artifactId>maven-clover2-plugin</artifactId> <version>3.1.10</version> <configuration> <singleCloverDatabase>true</singleCloverDatabase> <cloverDatabase>/absolute/path/to/clover.db</cloverDatabase> </configuration> </plugin>
Hello Atlassian Community! My name is Emilee, and I’m a Product Marketing Manager for the Marketplace team. Starting with this post, I'm kicking off a monthly series of Spotlights to highlight Ma...
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!
Unfortunately there are no AUG chapters near you at the moment.Start an AUG
We're bringing product updates and pro tips on teamwork to ten cities around the world.Save your spot