How to Check If Your Compiled Scala Code Contains Scoverage Instrumentation
When working on Scala projects, code coverage tools like sbt-scoverage are invaluable for ensuring your test suite covers critical logic. However, sbt-scoverage works by mutating your code during compilation—injecting measurement hooks and calls to coverage runtime libraries directly into your bytecode.
If a build pipeline runs sbt clean coverage test without running a clean non-coverage build before packaging, those coverage instructions will leak into your production binaries. This can lead to unexpected performance degradation, additional memory usage, and runtime errors if the Scoverage runtime dependency isn't packaged in your production environment.
In this guide, we will explore several straightforward methods to inspect compiled .class files or packaged .jar artifacts to verify if Scoverage instrumentation is present.
Method 1: Inspecting the JAR File Contents
Scoverage often embeds coverage data files or runtime packages directly into the generated artifacts depending on how your SBT assembly or packaging is configured. You can quickly list the contents of a .jar file using the standard Java archive tool: