本文介绍了如何在Play的主模块和子模块中设置jacoco4sbt来处理类?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我在使 jacoco4sbt 与我的Play 2.3.4项目一起工作时遇到一些问题. >

我的项目由3个子模块组成:commonapifrontend,并且在app根文件夹中没有代码.现在,当我运行Jacoco时,找不到子模块类.

检查target/scala-VERSION/classes我只找到一些路由类(实际上,这是我的"root"项目中仅有的代码,但我希望是因为我将所有这些项目汇总在一起,所以这些类就在那里了).

如果我将类从MODULE_NAME/target/scala-VERSION/classes复制到target/scala-VERSION/classes,然后运行Jacoco,我将得到预期的结果.

那么使它工作的最佳方法是什么?我在jacoco4sbt中找不到用于指定其他类位置的任何配置.

我的build.sbt文件

import Keys._

// Dummy value to deal with bug in sbt 0.13.5
val k = 0

name := "PlayApp"

version := "0.5.0"

// omitted resolvers part

scalaVersion := "2.10.4"

libraryDependencies ++= Seq(
    "com.edulify" %% "play-hikaricp" % "1.5.0" exclude("com.jolbox", "bonecp"),
    "com.novocode" % "junit-interface" % "0.11" % "test"
)

lazy val common = project.in(file("common")).enablePlugins(PlayJava)

lazy val frontend = project.in(file("frontend")).enablePlugins(PlayJava).dependsOn(common)

lazy val api = project.in(file("api")).enablePlugins(PlayJava).dependsOn(common)

lazy val main = project.in(file(".")).enablePlugins(PlayJava)
    .aggregate(frontend, api).dependsOn(frontend, api)

parallelExecution in Test := false

javaOptions in Test += "-Dconfig.resource=test.conf"

jacoco.sbt

import de.johoop.jacoco4sbt._
import JacocoPlugin._


jacoco.settings

Keys.fork in jacoco.Config := true

parallelExecution in jacoco.Config := false

jacoco.outputDirectory in jacoco.Config := file("target/jacoco")

jacoco.reportFormats in jacoco.Config := Seq(XMLReport("utf-8"), HTMLReport("utf-8"))

jacoco.excludes in jacoco.Config := Seq("views*", "*Routes*", "controllers*routes*", "controllers*Reverse*", "controllers*javascript*", "controller*ref*")

javaOptions in jacoco.Config  += "-Dconfig.resource=test.conf"
解决方案

jacoco.sbt添加到每个子项目,其内容如下:

jacoco.settings

p.s.我一直在寻找说服sbt将jacoco.settings应用于顶层根build.sbt中的每个子项目的方法,但无济于事.

I'm having some problems to make jacoco4sbt working with my Play 2.3.4 project.

My project is composed of 3 submodules: common, api and frontend and has no code in the app root folder. Now when I run Jacoco it does not find the submodules classes.

Inspecting target/scala-VERSION/classes I only find some routing classes (which in fact is the only code I have in my "root" project, but I was expecting that because I aggregate all those projects the classes would be there).

If I copy the classes from MODULE_NAME/target/scala-VERSION/classes to target/scala-VERSION/classes and then run Jacoco I get the expected result.

So what is the best way to make it work? I can't find any config in jacoco4sbt to specify additional classes locations.

My build.sbt file

import Keys._

// Dummy value to deal with bug in sbt 0.13.5
val k = 0

name := "PlayApp"

version := "0.5.0"

// omitted resolvers part

scalaVersion := "2.10.4"

libraryDependencies ++= Seq(
    "com.edulify" %% "play-hikaricp" % "1.5.0" exclude("com.jolbox", "bonecp"),
    "com.novocode" % "junit-interface" % "0.11" % "test"
)

lazy val common = project.in(file("common")).enablePlugins(PlayJava)

lazy val frontend = project.in(file("frontend")).enablePlugins(PlayJava).dependsOn(common)

lazy val api = project.in(file("api")).enablePlugins(PlayJava).dependsOn(common)

lazy val main = project.in(file(".")).enablePlugins(PlayJava)
    .aggregate(frontend, api).dependsOn(frontend, api)

parallelExecution in Test := false

javaOptions in Test += "-Dconfig.resource=test.conf"

jacoco.sbt

import de.johoop.jacoco4sbt._
import JacocoPlugin._


jacoco.settings

Keys.fork in jacoco.Config := true

parallelExecution in jacoco.Config := false

jacoco.outputDirectory in jacoco.Config := file("target/jacoco")

jacoco.reportFormats in jacoco.Config := Seq(XMLReport("utf-8"), HTMLReport("utf-8"))

jacoco.excludes in jacoco.Config := Seq("views*", "*Routes*", "controllers*routes*", "controllers*Reverse*", "controllers*javascript*", "controller*ref*")

javaOptions in jacoco.Config  += "-Dconfig.resource=test.conf"
解决方案

Add jacoco.sbt to every subproject with the following content:

jacoco.settings

p.s. I've been looking for ways to convince sbt to have jacoco.settings applied to every subproject in the top-level root build.sbt, but to no avail.

这篇关于如何在Play的主模块和子模块中设置jacoco4sbt来处理类?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

10-15 23:25