I have upgraded the java version of a scala application which is using sbt-jacoco
plugin to run and check the scalatest
coverage. After upgrading Java8 to Java11 I started getting an error which is mentioned below but it was working fine with Java8.
[error] java.io.IOException: Error while instrumenting class MonthTimeTrigger.class.
[error] at org.jacoco.core.instr.Instrumenter.instrumentError(Instrumenter.java:166)
[error] at org.jacoco.core.instr.Instrumenter.instrument(Instrumenter.java:117)
[error] at org.jacoco.core.instr.Instrumenter.instrument(Instrumenter.java:136)
Note: The above error I was getting whenever I used to use any Java code within the Scala application and try to run sbt jacoco
.
current scala application environment
I have only found the solution after some research. And the problem is with the sbt-jacoco
plugin itself as it does not support java10 onwards.
They (sbt-jacoco
) did some workaround for this problem and probably will get these things fixed in the 4.0 release.
For now, the workaround is to override some of the jacoco dependencies in either plugins.sbt
or build.sbt
:
// plugins.sbt
val jacocoVersion = "0.8.5"
dependencyOverrides ++= Seq(
"org.jacoco" % "org.jacoco.core" % jacocoVersion,
"org.jacoco" % "org.jacoco.report" % jacocoVersion,
"org.jacoco" % "org.jacoco.agent" % jacocoVersion)
// build.sbt
val jacocoVersion = "0.8.5"
dependencyOverrides ++= Seq(
"org.jacoco" % "org.jacoco.core" % jacocoVersion % Test,
"org.jacoco" % "org.jacoco.report" % jacocoVersion % Test,
"org.jacoco" % "org.jacoco.agent" % jacocoVersion % Test)
Note: Even if you override only org.jacoco.core
would work.