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>
Atlassian Summit is an excellent opportunity for in-person support, training, and networking.Learn more
...there's anything I've learnt from working, it's that people are lazy! No offense to anyone reading this, but it's true and we can all admit it. The easier you make something for someone, the more...
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
You're one step closer to meeting fellow Atlassian users at your local meet up. Learn more about AUGs