I have a project in Jenkins that I want to create a JaCoCo code coverage report.
If I run jacoco:test
then jacoco:report
locally it creates the correct files (.exec, .classes and sources) in myproject/target/scala-2.9.1/jacoco
so it works.
However when building on jenkins this only creates the classes directory meaning it picks up the code but not the test that cover it so I get 0% code coverage.
Has anyone got jacoco working with sbt in this way?
JaCoCo was originally written for Java and runs on the JVM, but because it's bytecode-based it works for Scala too.
To get code coverage reports in a Maven project, we first need to set up the JaCoCo Maven plugin for that project. By integrating the JaCoCo plugin, the results of the code coverage analysis can be reviewed as an HTML report. The current version of the JaCoCo-Maven plugin can be downloaded from the MVN Repository.
I was running into this same issue when trying to start a new Scala project. After trying a number of path configurations, I was able to figure a solution.
The default value for Path to class directories is **/classes
. I suspect the issue is that the pattern allows for matching target/scala-X.XX/classes/
and target/scala-X.XX/jacoco/classes/
.
Changing the class directory path to target/*/classes
allowed the Jenkins plug-in to start reporting the correct coverage information.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With