5
votes

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 !

3
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
Oh, I found it! Should you not have this problem, I wouldn't even know about this feature :) So, thank you!Tair
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

3 Answers

0
votes

It Looks like you already have

apply plugin: 'jacoco'

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"
0
votes

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?

-3
votes

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.