无法使用sbt4jacoco运行代码覆盖率

时间:2015-02-05 17:41:03

标签: sbt jacoco typesafe-activator

我正在关注jacoco4sbt wiki使用jacoco运行我现有项目的Junit测试用例。我在运行以下命令时遇到异常。

$ activator jacoco:cover
[info] Loading project definition from /data/test/project
[info] Set current project to test (in build file:/data/test/)
java.io.IOException: Error while instrumenting class Routes$$anonfun$routes$1.class.
    at org.jacoco.core.instr.Instrumenter.instrumentError(Instrumenter.java:152)
    at org.jacoco.core.instr.Instrumenter.instrument(Instrumenter.java:124)
    at de.johoop.jacoco4sbt.Instrumentation$$anonfun$instrumentAction$3.apply(Instrumentation.scala:49)
    at de.johoop.jacoco4sbt.Instrumentation$$anonfun$instrumentAction$3.apply(Instrumentation.scala:46)
    at scala.collection.TraversableLike$$anonfun$map$1.apply(TraversableLike.scala:244)
    at scala.collection.TraversableLike$$anonfun$map$1.apply(TraversableLike.scala:244)
    at scala.collection.mutable.ResizableArray$class.foreach(ResizableArray.scala:59)
    at scala.collection.mutable.ArrayBuffer.foreach(ArrayBuffer.scala:47)
    at scala.collection.TraversableLike$class.map(TraversableLike.scala:244)
    at scala.collection.AbstractTraversable.map(Traversable.scala:105)
    at de.johoop.jacoco4sbt.Instrumentation$class.instrumentAction(Instrumentation.scala:46)
    at de.johoop.jacoco4sbt.JacocoPlugin$jacoco$.instrumentAction(JacocoPlugin.scala:59)
    at de.johoop.jacoco4sbt.JacocoPlugin$SharedSettings$$anonfun$settings$5.apply(JacocoPlugin.scala:84)
    at de.johoop.jacoco4sbt.JacocoPlugin$SharedSettings$$anonfun$settings$5.apply(JacocoPlugin.scala:84)
    at scala.Function6$$anonfun$tupled$1.apply(Function6.scala:35)
    at scala.Function6$$anonfun$tupled$1.apply(Function6.scala:34)
    at scala.Function1$$anonfun$compose$1.apply(Function1.scala:47)
    at sbt.$tilde$greater$$anonfun$$u2219$1.apply(TypeFunctions.scala:42)
    at sbt.std.Transform$$anon$4.work(System.scala:64)
    at sbt.Execute$$anonfun$submit$1$$anonfun$apply$1.apply(Execute.scala:237)
    at sbt.Execute$$anonfun$submit$1$$anonfun$apply$1.apply(Execute.scala:237)
    at sbt.ErrorHandling$.wideConvert(ErrorHandling.scala:18)
    at sbt.Execute.work(Execute.scala:244)
    at sbt.Execute$$anonfun$submit$1.apply(Execute.scala:237)
    at sbt.Execute$$anonfun$submit$1.apply(Execute.scala:237)
    at sbt.ConcurrentRestrictions$$anon$4$$anonfun$1.apply(ConcurrentRestrictions.scala:160)
    at sbt.CompletionService$$anon$2.call(CompletionService.scala:30)
    at java.util.concurrent.FutureTask.run(FutureTask.java:262)
    at java.util.concurrent.Executors$RunnableAdapter.call(Executors.java:471)
    at java.util.concurrent.FutureTask.run(FutureTask.java:262)
    at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1145)
    at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:615)
    at java.lang.Thread.run(Thread.java:745)
Caused by: java.lang.RuntimeException: java.lang.ClassNotFoundException: play.api.mvc.Handler
    at org.objectweb.asm.ClassWriter.getCommonSuperClass(ClassWriter.java:1684)
    at org.objectweb.asm.ClassWriter.getMergedType(ClassWriter.java:1654)
    at org.objectweb.asm.Frame.merge(Frame.java:1426)
    at org.objectweb.asm.Frame.merge(Frame.java:1325)
    at org.objectweb.asm.MethodWriter.visitMaxs(MethodWriter.java:1475)
    at org.objectweb.asm.ClassReader.readCode(ClassReader.java:1554)
    at org.objectweb.asm.ClassReader.readMethod(ClassReader.java:1017)
    at org.objectweb.asm.ClassReader.accept(ClassReader.java:693)
    at org.objectweb.asm.ClassReader.accept(ClassReader.java:506)
    at org.objectweb.asm.ClassWriter.toByteArray(ClassWriter.java:995)
    at org.jacoco.core.instr.Instrumenter.instrument(Instrumenter.java:84)
    at org.jacoco.core.instr.Instrumenter.instrument(Instrumenter.java:122)
    at de.johoop.jacoco4sbt.Instrumentation$$anonfun$instrumentAction$3.apply(Instrumentation.scala:49)
    at de.johoop.jacoco4sbt.Instrumentation$$anonfun$instrumentAction$3.apply(Instrumentation.scala:46)
    at scala.collection.TraversableLike$$anonfun$map$1.apply(TraversableLike.scala:244)
    at scala.collection.TraversableLike$$anonfun$map$1.apply(TraversableLike.scala:244)
    at scala.collection.mutable.ResizableArray$class.foreach(ResizableArray.scala:59)
    at scala.collection.mutable.ArrayBuffer.foreach(ArrayBuffer.scala:47)
    at scala.collection.TraversableLike$class.map(TraversableLike.scala:244)
    at scala.collection.AbstractTraversable.map(Traversable.scala:105)
    at de.johoop.jacoco4sbt.Instrumentation$class.instrumentAction(Instrumentation.scala:46)
    at de.johoop.jacoco4sbt.JacocoPlugin$jacoco$.instrumentAction(JacocoPlugin.scala:59)
    at de.johoop.jacoco4sbt.JacocoPlugin$SharedSettings$$anonfun$settings$5.apply(JacocoPlugin.scala:84)
    at de.johoop.jacoco4sbt.JacocoPlugin$SharedSettings$$anonfun$settings$5.apply(JacocoPlugin.scala:84)
    at scala.Function6$$anonfun$tupled$1.apply(Function6.scala:35)
    at scala.Function6$$anonfun$tupled$1.apply(Function6.scala:34)
    at scala.Function1$$anonfun$compose$1.apply(Function1.scala:47)
    at sbt.$tilde$greater$$anonfun$$u2219$1.apply(TypeFunctions.scala:42)
    at sbt.std.Transform$$anon$4.work(System.scala:64)
    at sbt.Execute$$anonfun$submit$1$$anonfun$apply$1.apply(Execute.scala:237)
    at sbt.Execute$$anonfun$submit$1$$anonfun$apply$1.apply(Execute.scala:237)
    at sbt.ErrorHandling$.wideConvert(ErrorHandling.scala:18)
    at sbt.Execute.work(Execute.scala:244)
    at sbt.Execute$$anonfun$submit$1.apply(Execute.scala:237)
    at sbt.Execute$$anonfun$submit$1.apply(Execute.scala:237)
    at sbt.ConcurrentRestrictions$$anon$4$$anonfun$1.apply(ConcurrentRestrictions.scala:160)
    at sbt.CompletionService$$anon$2.call(CompletionService.scala:30)
    at java.util.concurrent.FutureTask.run(FutureTask.java:262)
    at java.util.concurrent.Executors$RunnableAdapter.call(Executors.java:471)
    at java.util.concurrent.FutureTask.run(FutureTask.java:262)
    at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1145)
    at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:615)
    at java.lang.Thread.run(Thread.java:745)
[error] (jacoco:fullClasspath) java.io.IOException: Error while instrumenting class Routes$$anonfun$routes$1.class.
[error] Total time: 5 s, completed Feb 5, 2015 10:36:58 PM

请参阅下面的build.sbt

name := "test"

version := "1.0-SNAPSHOT"

playJavaSettings

ebeanEnabled := false

jacoco.settings

playJavaSettings ++ QueryDSLPlugin.queryDSLSettings

val current = project.in(file(".")).configs(QueryDSLPlugin.QueryDSL)

libraryDependencies ++= Seq(
    javaCore,
    cache,
    javaJpa,
    javaJpa.exclude("org.hibernate.javax.persistence", "hibernate-jpa-2.0-api"),
    "org.apache.axis" % "axis" % "1.4",
    "org.apache.axis" % "axis-jaxrpc" % "1.4",
    "commons-discovery" % "commons-discovery" % "0.5",
    "wsdl4j" % "wsdl4j" % "1.6.2",
    "org.springframework" % "spring-context" % "4.1.0.RELEASE",
    "javax.inject" % "javax.inject" % "1",
    "org.springframework.data" % "spring-data-jpa" % "1.7.0.RELEASE",
    "org.springframework" % "spring-expression" % "4.1.0.RELEASE",
    "org.hibernate" % "hibernate-entitymanager" % "4.3.7.Final",
    "org.hibernate.javax.persistence" % "hibernate-jpa-2.1-api" % "1.0.0.Final",
    "org.apache.httpcomponents" % "httpclient" % "4.3.5",
    "org.json" % "json" % "20090211",
    "org.jasypt" % "jasypt" % "1.9.0",
    "org.mockito" % "mockito-core" % "1.9.5" % "test",
    "com.github.jknack" % "handlebars" % "1.3.2",
    "org.springframework" % "spring-context-support" % "3.2.2.RELEASE",
    "javax.mail" % "mail" % "1.5.0-b01",
    "com.typesafe.akka" % "akka-kernel_2.10" % "2.1.0",
    "org.quartz-scheduler" % "quartz" % "2.2.1",
    "org.quartz-scheduler" % "quartz-jobs" % "2.2.1",
    "com.datastax.cassandra" % "cassandra-driver-core" % "2.1.1",
    "com.datastax.cassandra" % "cassandra-driver-mapping" % "2.1.1",
    "junit" % "junit" % "4.11",
    "com.amazonaws" % "aws-java-sdk" % "1.9.6",
    "com.twilio.sdk" % "twilio-java-sdk" % "3.4.5",
    "com.atlassian.jira" % "jira-rest-java-client-core" % "2.0.0-m25",
    "com.atlassian.jira" % "jira-rest-java-client-api" % "2.0.0-m25",
    "commons-io" % "commons-io" % "2.2",
    "org.apache.commons" % "commons-csv" % "1.0",
    "com.jcraft" % "jsch" % "0.1.50",
    "net.sf.opencsv" % "opencsv" % "2.3",
    "com.google.guava" % "guava" % "18.0"
    )

和/project/plugins.sbt

// Comment to get more information during initialization
logLevel := Level.Warn

// The Typesafe repository
resolvers += "Typesafe repository" at "http://repo.typesafe.com/typesafe/releases/"

// Use the Play sbt plugin for Play projects
addSbtPlugin("com.typesafe.play" % "sbt-plugin" % "2.2.0")

addSbtPlugin("com.code-troopers.play" % "play-querydsl" % "0.1.1")

addSbtPlugin("de.johoop" % "jacoco4sbt" % "2.1.6")

我可以使用以下命令

查看可用的插件
$ activator about
[info] Loading project definition from /data/test/project
[info] Set current project to test (in build file:/data/test/)
[info] This is sbt 0.13.0
[info] The current project is {file:/data/test/}current 1.0-SNAPSHOT
[info] The current project is built against Scala 2.10.2
[info] Available Plugins: play.Project, com.typesafe.sbteclipse.plugin.EclipsePlugin, org.sbtidea.SbtIdeaPlugin, com.typesafe.sbt.SbtNativePackager, QueryDSLPlugin, de.johoop.jacoco4sbt.JacocoPlugin
[info] sbt, sbt plugins, and build definitions are using Scala 2.10.

此外,我可以使用以下命令运行测试用例。

$ activator test

我是否遗漏了jacoco4sbt的任何配置?

0 个答案:

没有答案