sbt / sbt-jacoco

an sbt plugin for JaCoCo Code Coverage
https://scala-sbt.org/sbt-jacoco/
Eclipse Public License 1.0
123 stars 67 forks source link

Jacoco and Sonar PlayFramework 2.6 #104

Open dorianboulch opened 6 years ago

dorianboulch commented 6 years ago

I'm using sbt-jacoco with a Play Framework (v2.6) and Sonar (sbt-sonar-scanner-plugin). When I run sbt jacoco and then sbt sonar I have this error : (*:sonar) java.lang.IllegalStateException: Line 13 is out of range in the file app/model/MyModel.java (lines: 10)

In Play, there is by default a plugin "sbt-play-enhancer" that generates getters/setters automatically. I suppose sonar doesn't execute this plugin but jacoco yes. This would explain the difference of number of line in the java file.

Have you got an idea about how to solve this ?

I tried this and many other configurations in my build.sbt file:


sonarProperties ++= Map(
  "sonar.host.url" -> "http://localhost:9000",
  "sonar.login" -> "mytoken",
  "sonar.projectKey" -> "myProjectKey",
  "sonar.projectVersion" -> version.value,
  "sonar.junit.reportPaths" -> "target/test-reports",
  "sonar.jacoco.reportPaths" -> "target/scala-2.12/jacoco/data/jacoco.exec",
  "sonar.sourceEncoding" -> "UTF-8",
  "sonar.sources" -> sourceDirectory.in(Compile).value.absolutePath,
  "sonar.tests" -> sourceDirectory.in(Test).value.absolutePath,
  "sonar.java.binaries" -> classDirectory.in(Compile).value.absolutePath,
  "sonar.java.test.binaries" -> classDirectory.in(Test).value.absolutePath,
  "sonar.java.libraries" -> dependencyClasspath.in(Compile).value
    .map(p => p.data.absolutePath)
    .mkString(","),
  "sonar.java.test.libraries" -> dependencyClasspath.in(Test).value
    .map(p => p.data.absolutePath)
    .filter(s => s.endsWith(".jar"))
    .mkString(",")
)

jacocoInstrumentedDirectory := classDirectory.in(Compile).value

Environment

dorianboulch commented 6 years ago

Someone to help me ?

dorianboulch commented 6 years ago

Is this repo still maintained?

MarkJiaLinWu commented 6 years ago

the same to you . I don't have the coverage showed in sonar

abdelrahmanmohamed1990 commented 2 years ago

having the same issue play 2.8

sairamyadavg commented 2 years ago

having the same issue play 2.8

Can you provide sonar version which you are using? Report generation is dependent on sonar version