【问题标题】:Jacoco: unable to read execution data file, ant taskJacoco:无法读取执行数据文件,ant任务
【发布时间】:2016-03-17 17:58:58
【问题描述】:

信息: java版本:1.8.0_66 蚂蚁版本:1.9.6

我想做什么:

为在 AWS windows 2k12 服务器上运行的服务器代码提供代码覆盖率报告。

我做了什么:

  • 完全停止服务器。
  • 将 jacocoagent.jar 放入服务器的 bin 文件夹中。注意:这是在 Program Files 文件夹中
  • 将 -javaagent 设置附加到服务器启动期间使用的 JAVA_OPTS。
  • 启动服务器。
  • 从我的本地笔记本电脑运行我的示例测试。
  • 完全停止服务器。这产生了一个 184kb 的 jacoco.exec。
  • 将我的 build.xml 复制到 jacoco.exec 所在的同一目录。 C:/path/to/exec/jacoco.exec
  • 已将 jacocoant.jar 复制到 C:/path/to/jacocoant.jar
  • cd 到 C:/path/to/exec/ 并运行命令“ant”

结果:

出错无法读取执行数据文件 C:/path/to/exec/jacoco.exec

构建.xml:

<project name="Example" default="rebuild" xmlns:jacoco="antlib:org.jacoco.ant">

<description>
  Example Ant build file that demonstrates how a JaCoCo coverage report
  can be itegrated into an existing build in three simple steps.
</description>

<property name="result.dir" location="." />
<property name="result.classes.dir" location="${result.dir}/path/to/classes" />
<property name="result.report.dir" location="${result.dir}/report" />
<property name="result.exec.file" location="${result.dir}/jacoco.exec" />

<!-- Step 1: Import JaCoCo Ant tasks -->
<taskdef uri="antlib:org.jacoco.ant" resource="org/jacoco/ant/antlib.xml">
    <classpath path="../jacocoant.jar" />
</taskdef>

<target name="clean">
    <delete dir="${result.report.dir}" />
</target>

<target name="report">
    <!-- Step 3: Create coverage report -->
    <jacoco:report>

        <!-- This task needs the collected execution data and ... -->
        <executiondata>
            <file file="${result.exec.file}" />
        </executiondata>

        <!-- the class files and optional source files ... -->
        <structure name="JaCoCo Code Coverage Report">
            <classfiles>
                <fileset dir="${result.classes.dir}" >
                    </fileset>
            </classfiles>
            <sourcefiles encoding="UTF-8">
                <fileset dir="${src.dir}" />
            </sourcefiles>
        </structure>

        <!-- to produce reports in different formats. -->
        <html destdir="${result.report.dir}" />
        <csv destfile="${result.report.dir}/report.csv" />
        <xml destfile="${result.report.dir}/report.xml" />
    </jacoco:report>
</target>

我不确定问题出在 exec 文件(它可能已损坏)还是我的整个设置。 任何识别和帮助解决问题的帮助都非常感谢!!!

谢谢!

【问题讨论】:

  • 你找到答案了吗?

标签: java ant code-coverage jacoco


【解决方案1】:

我在使用 gradle 和 jaCoCo 时得到了这个。

我删除了 build/ 目录并重新运行 ./gradlew jacocoTestReport,这一次通过了。

【讨论】:

    【解决方案2】:

    类似于@sofia 的解决方案,但对于 gradle: 我删除了工具版本之后的版本。而不是

    allprojects {
        jacoco {
            toolVersion = '0.7.1.201405082137'
        }
    }
    

    我用了以下

    allprojects {
        jacoco {
            toolVersion = '0.7.1'
        }
    }
    

    【讨论】:

      【解决方案3】:

      我最近遇到了同样的问题,我花了很长时间才弄清楚。我希望我如何解决这个问题会对您或其他人有所帮助。

      1. 使用ant -verbose report查看详细信息。我使用“ant -verbose report”并收到此消息:“java.io.IOException: Incompatible version 1007”。
      2. 当我使用 maven 时,我在我的 pom.xml 中添加了以下几行。注意:版本与您的 javaagent 的版本相同。

      &lt;dependency&gt; &lt;groupId&gt;org.jacoco&lt;/groupId&gt; &lt;artifactId&gt;org.jacoco.ant&lt;/artifactId&gt; &lt;version&gt;0.7.4.201502262128&lt;/version&gt; &lt;/dependency&gt;

      最终,报表生成成功。

      【讨论】:

        猜你喜欢
        • 2020-10-23
        • 2016-09-17
        • 2015-04-07
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        相关资源
        最近更新 更多