Skip to content

Adding scoverage plugin broke running tests via idea with java.lang.NoClassDefFoundError: scoverage/Invoker$ #272

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Closed
apple-corps opened this issue Dec 20, 2018 · 4 comments

Comments

@apple-corps
Copy link

apple-corps commented Dec 20, 2018

I've become accustomed to running my ScalaTest unit tests via idea. Then I added the scoverage plugin and ran the tests via sbt from shell and got coverage reports as documented.

Then when I went back to idea to run a single test I got the discussed java.lang.NoClassDefFoundError: scoverage/Invoker$

I tried adding libraryDependencies += "org.scoverage" %% "scalac-scoverage-runtime" % "1.5.1" as suggested in #115 but it didn't work.

I'm putting my relatively clean and simple build.sbt below.

Why does idea need to use this invoker when running a single test via the UI?

name := "scala-org-kafka"
version := ".1"
scalaVersion := "2.11.8"
organization := "org.example.scala"

libraryDependencies += "org.scalactic" %% "scalactic" % "3.0.1"
libraryDependencies += "org.scalatest" %% "scalatest" % "3.0.1" % "test"
libraryDependencies += "org.apache.spark" %% "spark-sql" % "2.4.0"
libraryDependencies += "org.apache.spark" % "spark-streaming_2.11" % "2.4.0"
libraryDependencies += "org.apache.spark" % "spark-streaming-kafka-0-10_2.11" % "2.4.0"
libraryDependencies += "org.apache.spark" %% "spark-sql-kafka-0-10" % "2.4.0"

mainClass in assembly := Some("org.example.scala.SparkContextProvider")
assemblyMergeStrategy in assembly := {
  case "META-INF/services/org.apache.spark.sql.sources.DataSourceRegister" => MergeStrategy.concat
  case PathList("META-INF", xs @ _*) => MergeStrategy.discard
  case _ => MergeStrategy.first
@gslowikowski
Copy link
Member

Hi @Drocsid

Unfortunately Idea runs test on instrumented classes left in target/scala-2.11/classes directory after you run tests with Scoverage. SBT process was properly configured (by coverage task) to run tests with scalac-scoverage-runtime dependency added to classpath.
Idea is not configured and you should not add scalac-scoverage-runtime dependency to the build manually.

To get Scoverage reports, I would call:

sbt coverage test coverageReport coverageOff compile

After recompilation with Scoverage disabled you end up with uninstrumented classes on disk which have no scalac-scoverage-runtime dependency.

@apple-corps
Copy link
Author

Ahh ok. I will try now as suggested. But I thought I tried sbt clean after and still getting the java.lang.NoClassDefFoundError: scoverage/Invoker$ error. Anyhow thanks for the quick response.

I'm not sure how many other people are doing things similar to me, but maybe add this to the readme if it's a common pattern?

@apple-corps
Copy link
Author

apple-corps commented Dec 20, 2018

I can confirm that your suggestion resolved my issue. Also is there a way I can send a donation to the project or beer money or something?

@gslowikowski
Copy link
Member

gslowikowski commented Jan 6, 2019

We can drink a beer if you will visit Cracow in Poland.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants