How to get JaCoCo coverage with Sonar in Jenkins?
Solution 1
They just released what you need : https://wiki.jenkins-ci.org/display/JENKINS/JaCoCo+Plugin
Solution 2
Providing an answer for the next poor soul who spends hours trying to find out why this doesn't work. Apparently this feature has been removed:
Remove "sonar.jacoco.antTargets" property and related classes in the plugin
Solution 3
One possibility is that the name of your ant task for junit does not match the name specified in the properties.
You have specified
sonar.jacoco.antTargets=test-with-coverage
As per the documentation, there should be an ant target with exactly the same name. Also in this target, junit should be set to fork as well.
jdtangney
Bringing Lean and UX to Security and Privacy, and vice versa
Updated on June 24, 2022Comments
-
jdtangney almost 2 years
I followed the instructions here
I am NOT using Maven.My Jenkins job output says: 12:32:33.951 INFO Sensor JaCoCoSensor... 12:32:33.961 INFO Project coverage is set to 0% as no JaCoCo execution data has been dumped: /var/lib/jenkins/workspace/SeqGen/SeqGen/jacoco.exec 12:32:35.152 INFO Sensor JaCoCoSensor done: 1201 ms
Here are my properties:
project.home=SeqGen sonar.projectKey=com.skyboximaging:seqgen sonar.projectName="SeqGen" sonar.projectVersion=1.0 sonar.dynamicAnalysis=true sources=src/java tests=test/java binaries=classes sonar.jacoco.reportPath=jacoco.exec sonar.jacoco.antTargets=test-with-coverage
On the Sonar server, I set General Settings > Code Coverage > Code coverage plugin to jacoco
I am very confused by the documentation at http://docs.codehaus.org/display/SONAR/Code+coverage+plugins I am particularly puzzled by this sentence: "During Sonar analysis, the Sonar Jacoco plugin will take care to attach the Jacoco agent to the JVM and to launch the unit tests."
As far as I can tell, my Ant target is not getting invoked. How does the Sonar Jacoco plugin know where to find my build.xml?
What am I doing wrong?
-
Mark O'Connor over 12 yearsAnother "gotcha from the doco:- Only specified targets would be executed. So for instance, if "test" target depends on a "compile" target, Jacoco plugin will only execute "test" target without executing first the "compile" target. In such case, a solution can be to update the "sonar" target in order declare a dependency on the "compile" target
-
Soid over 11 yearsCould you describe a bit more the problem that you solved? As I understood you told about issues.jenkins-ci.org/browse/JENKINS-14927 but there was not descriptions there. How can we use code coverage with jenkins & sonar & ant ?
-
Pulak Agrawal over 11 years@GregoryLo sorry did not understand ? Did you mean to post this here as I have not contributing anything for this issue