无法通过Jacoco ant和SonarQube查看代码覆盖率结果

时间:2014-02-25 08:15:27

标签: ant jenkins jacoco sonarqube

我希望在我的SonarQube 3.2.1中看到测试覆盖率报告,但看不到任何内容,并且在我的构建中出现以下错误:

00:11:17.747 INFO  o.s.p.j.JaCoCoPlugin - Analysing /home/jenkins/workspace/.../build/codeCoverageReport/jacoco.exec
00:11:17.795 WARN  o.s.p.j.JaCoCoPlugin - Coverage information was not collected. Perhaps you forget to include debug information into compiled classes?

我执行Jacoco Ant报告任务:

<target name="compile-tests" depends="compile">
  <javac includeantruntime="false"
    debug="true" debuglevel="lines,vars,source"
    executable="${jdk1.5.home}/bin/javac" 
    fork="true"
    srcdir="${src-test.dir}" destdir="${build-test.dir}"
    classpathref="classpath-test"
    encoding="UTF-8"
  />
</target>
<target name="whatever">
  <jacoco:coverage destfile="${workspace.dir}/build/codeCoverageReport/jacoco.exec" xmlns:jacoco="antlib:org.jacoco.ant">
    <junit fork="true" jvm="${jdk1.5.home}/jre/bin/java" printsummary="yes" forkmode="once">
      <classpath>
        <path refid="classpath-test"/>
        <path location="${build-test.dir}"/>
      </classpath>
      <formatter type="plain"/>
      <formatter type="xml"/>
      <batchtest todir="${workspace.dir}/42-SSW/build/tuReport">
        <fileset dir="${src-test.dir}">
          <include name="**/*Test.java"/>
        </fileset>
      </batchtest>
    </junit>
  </jacoco:coverage>
</target>

Jacoco版本为0.5.10.201208310627(由SonarQube 3.2.1使用) 在Jenkins的帮助下,我正在使用以下conf来调用独立的声纳分析:

# required metadata
sonar.projectKey=foo.bar
sonar.projectName=baz
sonar.projectVersion=1.0
sonar.verbose=true

# path to source directories (required)
sources=\
42-SSW/log4jAppender/src,\
42-SSW/webservicesCommun/src,\
42-SSW/webservicesMetier/src,\
...

# path to test source directories (optional)
tests=\
42-SSW/log4jAppender/test,\
42-SSW/webservicesCommun/test,\
42-SSW/webservicesMetier/test,\
...

# path to project binaries (optional), for example directory of Java bytecode
binaries=\
42-SSW/log4jAppender/build/jar,\
42-SSW/webservicesCommun/build/jar,\
42-SSW/webservicesMetier/build/jar,\
...

# optional comma-separated list of paths to libraries. Only path to JAR file and path to directory of classes are supported.
libraries=\
40-WAS/wsa/lib/servlet-api.jar,\
40-WAS/wsa/lib/axis.jar,\
...

# Uncomment those lines if some features of java 5 or java 6 like annotations, enum, ...
# are used in the source code to be analysed
sonar.java.source=1.5
sonar.java.target=1.5
sonar.sourceEncoding=UTF-8
sonar.dynamicAnalysis=reuseReports
sonar.surefire.reportsPath=42-SSW/build/tuReport
sonar.java.coveragePlugin=jacoco
sonar.jacoco.reportPath=42-SSW/build/codeCoverageReport/jacoco.exec

有什么想法吗?

2 个答案:

答案 0 :(得分:0)

面临同样的问题。通过进行以下更改,我能够获得声纳的覆盖范围。[注意:在我的情况下,它的build.xml]

<property name="sonar.core.coveragePlugin" value="jacoco" />
<property name="sonar.junit.reportsPath" value="${build.dir}/test-report"/>
<property name="sonar.jacoco.reportPath" value="${build.dir}/jacoc.exec" />

在“编译”目标中包含调试信息。

<javac srcdir="${src}:${test}" destdir="${bin}" target="1.7" debug="on" 
source="1.7" encoding="cp1252">
<classpath refid="compileclasspath" />
</javac>

答案 1 :(得分:-2)

在你的错误日志中,它是sais:

00:11:17.795 WARN  o.s.p.j.JaCoCoPlugin - Coverage information was not collected. Perhaps you forget to include debug information into compiled classes?

查看您的ant脚本,您似乎可以使用调试信息编译测试源。您是否也使用调试信息编译测试所涵盖的源?

由于它似乎是一个与jacoco相关的问题,我还会指向jacoco-FAQ: http://www.eclemma.org/jacoco/trunk/doc/faq.html