jacoco的prepare-agent没有生成jacoco.exec文件

Gil*_*ili 17 maven jacoco

我正在运行Jacoco的Maven插件.该prepare-agent目标运行正常,但不会产生jacoco.exec由于某种原因文件.随后report目标抱怨Skipping JaCoCo execution due to missing execution data file.

有任何想法吗?

Gil*_*ili 33

阅读https://groups.google.com/forum/#!topic/jacoco/LzmCezW8VKA后,发现prepare-agent设置了一个名为的surefire属性argLine.如果你覆盖这个属性(https://issues.apache.org/jira/browse/SUREFIRE-951鼓励你这样做)那么jacoco永远不会运行.

解决方案是替换:

<argLine>-Dfile.encoding=${project.build.sourceEncoding}</argLine>
Run Code Online (Sandbox Code Playgroud)

<argLine>-Dfile.encoding=${project.build.sourceEncoding} ${argLine}</argLine>
Run Code Online (Sandbox Code Playgroud)

意思是,将jacoco附加argLine到新值.

更新:正如指出的饲料,如果你并不总是运行JaCoCo并没有其他的插件集${argLine},然后Maven会抱怨说,${argLine}是不确定的.要解决此问题,只需定义${argLine}跳过JaCoCo时应该是什么样子:

<properties>
    <argLine/>
</properties>
Run Code Online (Sandbox Code Playgroud)

在这种情况下使用@ {} argLine代替$ {} argLine作为解释在这里.

  • 如果您正在使用Tycho(对于Eclipse插件和应用程序),请使用$ {tycho.testArgLine}而不是$ {argLine}. (2认同)