Collectives™ on Stack Overflow

Find centralized, trusted content and collaborate around the technologies you use most.

Learn more about Collectives

Teams

Q&A for work

Connect and share knowledge within a single location that is structured and easy to search.

Learn more about Teams

I have very successfully integrated Gradle (1.11), Sonar ( 4.1.1 ), Java, Scala and Jacoco in my build process. I even managed to get info regarding the number of successful tests ( thanks to Stackoverflow! ). I have one problem though.

I can't seem to get info about coverage per test. It would be very nice to have this info.

> 15:11:16.514 INFO - Sensor JaCoCoSensor... 15:11:16.535 INFO -
> Analysing C:\example\gradle-sonar-jacoco-scala\build\jacoco\test.exec
> 15:11:17.887 INFO - No information about coverage per test.

A simplified version of the project is at : https://github.com/sebastianharko/gradle-sonar-java-jacoco-scalatest-junit

Cheers !

Are you sure there is such a feature in Sonar? Can you please show some pointers? I'm also evaluating sonar+maven, but didn't get farther than observing overall code coverage. – Tair Mar 1, 2014 at 18:03 Oh, I found it! Should you not have this problem, I wouldn't even know about this feature :) So, thank you! – Tair Mar 1, 2014 at 18:23 Your github example is for scala code that tests java code. Have you tested coverage reporting with scala testing scala or java testing java? I ask because I have gradle building some scala projects and it always shows compilation and testing of scala and java separately. – n0741337 Mar 7, 2014 at 5:24

in your gradle.build

But i'm not seeing a definition to where it's to get it file from in the gradle.build

jacoco {
  destinationFile = file("$buildDir/jacoco/test.exec")

If you plan on doing integration and unit testing it would look similar to the following:

task "integtest"(type: Test, dependsOn: integtestClasses) {
testClassesDir = sourceSets.integtest.output.classesDir
classpath = sourceSets.integtest.runtimeClasspath
  jacoco {
      destinationFile = file("$buildDir/jacoco/integTest.exec")
test {
  jacoco {
    destinationFile = file("$buildDir/jacoco/test.exec")

With the corresponding sonar configuration items

 property "sonar.jacoco.reportPath", "$buildDir/jacoco/test.exec"
 property "sonar.jacoco.itReportPath", "$buildDir/jacoco/integTest.exec"
                Thanks a lot for the reply but it does not solve my problem : 1 ) I don't have any integration testing at this point, just unit testing; 2) Jacoco is working fine, the code coverage is displayed in the Sonar Web Interface ; The problem is that I don't see "coverage per individual test" .. so If I have a test called test1() and a test called test2() , I would like to see that test1() covers 10% of the code, test2() covers 30% of the code, for example.
– MadSeb
                Feb 28, 2014 at 21:45
                According to the code that I see in github your telling sonar to look at the jacoco file without specifying jacoco where to put the .exec.  Which is where setting the destination file comes into play.
– RGG
                Feb 28, 2014 at 21:54
                well sonar somohow does figure out where the jacoco file is : See the original post : "Analysing C:\example\gradle-sonar-jacoco-scala\build\jacoco\test.exec" ; so the jacoco file location does not seem to be the problem but I will double check;
– MadSeb
                Feb 28, 2014 at 22:06
                that's because you have it defined at the bottom with the rest of your sonar config.  property "sonar.jacoco.reportPath", "$buildDir/jacoco/test.exec"
– RGG
                Feb 28, 2014 at 22:08

I've seen another conf parameters from SonarQube - integrationTest.exec - sonarRunner (Gradle) or "sonar-runner" command - showing 0.0% covereage :

The parameter sonar.java.coveragePlugin=jacoco called my attention. Did you try that?

I will double check but as I said before Sonar does manage to see and process the Jacoco file; – MadSeb Feb 28, 2014 at 22:08

You may also want to use Coveralls.io

It's very cheap: only $4.99/mo. and you would have a deep integration with your pull requests on Github (track when a branch increases or decreases your code coverage) as well as a very nice UI to drill down into your code coverage.

Both SBT and Gradle integrations are available.

Thanks for contributing an answer to Stack Overflow!

  • Please be sure to answer the question. Provide details and share your research!

But avoid

  • Asking for help, clarification, or responding to other answers.
  • Making statements based on opinion; back them up with references or personal experience.

To learn more, see our tips on writing great answers.