scoverage/sbt-scoverage

java.io.FileNotFoundException: .../build/service/target/scala-2.11/scoverage-data/scoverage.measurements.1 (No such file or directory)

sfosdal opened this issue · 9 comments

I am getting the following error when running an assembled jar:

Exception in thread "main" java.lang.ExceptionInInitializerError
	at com.avvo.data.qa_recommendation.service.Main$.delayedEndpoint$com$avvo$data$qa_recommendation$service$Main$1(Main.scala:13)
	at com.avvo.data.qa_recommendation.service.Main$delayedInit$body.apply(Main.scala:11)
	at scala.Function0$class.apply$mcV$sp(Function0.scala:34)
	at scala.runtime.AbstractFunction0.apply$mcV$sp(AbstractFunction0.scala:12)
	at scala.App$$anonfun$main$1.apply(App.scala:76)
	at scala.App$$anonfun$main$1.apply(App.scala:76)
	at scala.collection.immutable.List.foreach(List.scala:392)
	at scala.collection.generic.TraversableForwarder$class.foreach(TraversableForwarder.scala:35)
	at scala.App$class.main(App.scala:76)
	at com.avvo.data.qa_recommendation.service.Main$.main(Main.scala:11)
	at com.avvo.data.qa_recommendation.service.Main.main(Main.scala)
Caused by: java.io.FileNotFoundException: /opt/qa-recommendation/build/service/target/scala-2.11/scoverage-data/scoverage.measurements.1 (No such file or directory)
	at java.io.FileOutputStream.open0(Native Method)
	at java.io.FileOutputStream.open(FileOutputStream.java:270)
	at java.io.FileOutputStream.<init>(FileOutputStream.java:213)
	at java.io.FileWriter.<init>(FileWriter.java:107)
	at scoverage.Invoker$$anonfun$1.apply(Invoker.scala:42)
	at scoverage.Invoker$$anonfun$1.apply(Invoker.scala:42)
	at scala.collection.concurrent.TrieMap.getOrElseUpdate(TrieMap.scala:901)
	at scoverage.Invoker$.invoked(Invoker.scala:42)
	at com.avvo.data.qa_recommendation.service.BuildInfo$.<init>(BuildInfo.scala:8)
	at com.avvo.data.qa_recommendation.service.BuildInfo$.<clinit>(BuildInfo.scala)
	... 11 more

In my build.sbt I do have:
coverageEnabled := true

however when assembling use the following:
sbt -no-colors coverageOff assembly

I am currently using version 1.5.0:
addSbtPlugin("org.scoverage" % "sbt-scoverage" % "1.5.0")

with sbt: 0.13.15

coverageOff doesn't override coverageEnabled := true setting. Instead of using coverageEnabled := true, just call coverage (or coverageOn) to turn coverage on.

finally found time to try this. worked great for me. Thanks!

I have these two lines in the build.sbt of my single module sbt project,

coverageEnabled.in(Test, test) := true
coverageEnabled in(Compile, compile) := false

I still do see this error, when I build the jar file with assembly.

@naveencotha-zt provide a simple test project, please.

@gslowikowski posted it here, with a very simple readme

@naveencotha-zt don't run assembly task when coverage is turned on.

Proper calls:

sbt clean coverage test coverageReport coverageOff assembly

or

sbt clean assembly coverage test coverageReport

(BTW semicolons are not required when you specify tasks without quotation marks)

Thanks for the clarification, so if I do something like sbt clean coverage test coverageReport coverageOff assembly

  1. This makes tests run twice, to make the tests run only once, the command looks like
    sbt clean coverage test coverageReport coverageOff "set test in assembly := {}" assembly, Is there an elegant way?

  2. Can I remove these two lines from my sbt

ad. 1 - your test project contains no tests :)
ad. 2 - yes, remove these lines

Thanks, @gslowikowski, yeah you are right, I don't have any tests in the sample project, although I do have tests in my actual project.