Sounds simple: I want to deploy the project artifact (jar) while generating Clover code coverage reports and use them in Sonar. So, the Maven goal is just "clean deploy" and selecting the Clover and Sonar options in Bamboo. Well, does not work.
[Clover provides test code coverage information for Java, Bamboo is a Constant Integation tool, Sonar is a code quality tool, Maven is a Java build tool]
The main problem is that the Clover instrumented classes don't work with javadoc nor Sonar, and I want the clover report to be used in Sonar. Would be easy, if you could just clean the target/classes directory. Works also nicely if you add cobatura:cobatura before sonar:sonar, but who wants to run the unit tests three times?
After some time experimenting with various options, here is what I did:
(I am using the more-or-less current versions of the products)
The Maven goal is
"clean deploy sonar:sonar site clover2:setup verify clover2:clover clover2:save-history".
This runs the tests, creates the jars, runs Sonar with Findbugs, Checkstyle, PMD and produces the site with javadoc, etc. Everything nice. Then Clover creates the instrumented code and runs the tests again and creates the reports.
For Clover you need to save the reports by modifying your pom.xml. I did that in the parent pom under
<build><pluginManagement><plugins>
<plugin>
<groupId>com.atlassian.maven.plugins</groupId>
<artifactId>maven-clover2-plugin</artifactId>
<configuration>
<cloverDatabase>/var/bamboo-home/cloverDB/${project.artifactId}</cloverDatabase>
<outputDirectory>/var/bamboo-home/cloverOutput/${project.artifactId}</outputDirectory>
<generateHistorical>true</generateHistorical>
<historyDir>/var/bamboo-home/cloverHistory/${project.artifactId}</historyDir>
</configuration>
</plugin>
This moves the output away from the "target" directory and can be referenced later. Part of that you need to do anyway if you want historial reporting and to aggregate multiple projects.
As the Bamboo can access Artifacts only with the project, you need to create a link from the project directory, e.g.:
ln -s cloverOutput /var/bamboo-home/cloverOutput/foundation
In Bamboo, you need to indicate that the build is already integrated and change the Clover XML Location, e.g. to cloverOutput/clover.xml (in the Builder tab) - In the Artifacts tab delete the default Clover entry and create one with the Source directory of cloverOutput and **/*.* copy pattern.
Sonar actually picks up the previous coverage report, so you need to be aware that the coverage information within Sonar is one build old. For the latest, you would go to the Clover reports directly.
So I did not manage to find a way to do everything in one go. My guess to achieve that is to run Clover within Sonar. I happen to like the Clover reports, so that is one price to pay.
The best option though would be if Clover would have a "tear-down" option to remove the instrumented code.
Let me know if you know a better way.
... so now you know what I an doing for fun on a cloudy Sunday.