我们使用以下版本在SonarQube上获取JaCoCo代码覆盖率报告。
SonarQube 5.6.6 JaCoCo 0.7.9 Apache Ant 1.10.1 JUnit 4.12 JMockIt 1.20
我们每晚执行Jenkins工作以使用SonarQube执行代码分析。我们执行JUnit案例并收集应用程序的代码覆盖率。
作为Ant构建的一部分,我们执行以下步骤作为Sonar快照执行的一部分。 1)构建应用程序 2)执行JUnit案例 3)代码覆盖率 4)声纳分析
现在我们经常在Jenkins声纳作业中显示失败,因为SonarQube分析失败并且无法在Sonar服务器上应用快照。如果我们手动执行Ant声纳目标,那么我们就成功了,快照生成时代码覆盖没有任何问题。
[sonar:sonar] Sensor SurefireSensor
[sonar:sonar] parsing D:\Projects\Collaborate\Branches\R4_3\deployment\latest
[sonar:sonar] Resource not found: junit.framework.JUnit4TestCaseFacade
[sonar:sonar] Sensor SurefireSensor (done) | time=3343ms
[sonar:sonar] Sensor JaCoCoSensor
[sonar:sonar] Analysing D:\Projects\Collaborate\Branches\R4_3\deployment\latest\jacoco.exec
BUILD FAILED
D:\Projects\Collaborate\Branches\R4_3\deployment\build.xml:2246:
org.sonar.squidbridge.api.AnalysisException: Unable to read
D:\Projects\Collaborate\Branches\R4_3\deployment\latest\jacoco.exec
at org.sonar.plugins.jacoco.JacocoReportReader.readJacocoReport(JacocoReportReader.java:78)
at org.sonar.plugins.jacoco.AbstractAnalyzer.readExecutionData(AbstractAnalyzer.java:140)
at org.sonar.plugins.jacoco.AbstractAnalyzer.analyse(AbstractAnalyzer.java:114)
at org.sonar.plugins.jacoco.JaCoCoSensor.analyse(JaCoCoSensor.java:57)
at org.sonar.batch.phases.SensorsExecutor.executeSensor(SensorsExecutor.java:58)
at org.sonar.batch.phases.SensorsExecutor.execute(SensorsExecutor.java:50)
at org.sonar.batch.phases.AbstractPhaseExecutor.execute(AbstractPhaseExecutor.java:83)
at org.sonar.batch.scan.ModuleScanContainer.doAfterStart(ModuleScanContainer.java:192)
at org.sonar.core.platform.ComponentContainer.startComponents(ComponentContainer.java:142)
at org.sonar.core.platform.ComponentContainer.execute(ComponentContainer.java:127)
at org.sonar.batch.scan.ProjectScanContainer.scan(ProjectScanContainer.java:241)
at org.sonar.batch.scan.ProjectScanContainer.scanRecursively(ProjectScanContainer.java:236)
at org.sonar.batch.scan.ProjectScanContainer.doAfterStart(ProjectScanContainer.java:226)
at org.sonar.core.platform.ComponentContainer.startComponents(ComponentContainer.java:142)
at org.sonar.core.platform.ComponentContainer.execute(ComponentContainer.java:127)
at org.sonar.batch.task.ScanTask.execute(ScanTask.java:47)
at org.sonar.batch.task.TaskContainer.doAfterStart(TaskContainer.java:86)
at org.sonar.core.platform.ComponentContainer.startComponents(ComponentContainer.java:142)
at org.sonar.core.platform.ComponentContainer.execute(ComponentContainer.java:127)
at org.sonar.batch.bootstrap.GlobalContainer.executeTask(GlobalContainer.java
Total time: 21 minutes 19 seconds
以下是Ant“声纳”目标配置。
<target name="sonar" depends="init" xmlns:sonar="antlib:org.sonar.ant">
<taskdef uri="antlib:org.sonar.ant" resource="org/sonar/ant/antlib.xml">
<classpath>
<pathelement path="../../SONARlib/sonarqube-ant-task-2.4.jar" />
</classpath>
</taskdef>
<tstamp>
<format property="sonar_starttime" pattern="dd_MM_yyyy_HH_mm" />
</tstamp>
<echo>Sonar Scan Start Time:${sonar_starttime}</echo>
<property name="sonar.projectBaseDir"
value="<project_dir>" />
<property name="sonar.host.url" value="<sonar_server>" />
<property name="sonar.login"
value="<sonar_token>" />
<property name="sonar.projectKey" value="<project_key>" />
<property name="sonar.projectName" value="<project_name>" />
<property name="sonar.projectVersion" value="(R4_3)_${sonar_starttime}" />
<property name="sonar.analysis.mode" value="publish" />
<property name="sonar.language" value="java" />
<property name="sonar.java.source" value="1.8" />
<property name="sonar.sourceEncoding" value="UTF-8" />
<property name="sonar.sources" value="src/java,src/gradleSource" />
<property name="sonar.inclusions" value="**/*.java" />
<property name="sonar.tests" value="src/tests" />
<property name="sonar.test.inclusions" value="**/*Test.java" />
<property name="sonar.test.exclusions"
value="**/*SuiteTest.java,**/*Expectation.java" />
<property name="sonar.java.binaries" value="${build.root}/${appname}/WEB-
INF/classes" />
<property name="sonar.java.test.binaries"
value="${build.root}/${appname}/WEB-INF/classes" />
<property name="sonar.java.libraries"
value="${env.JAVA_HOME}/jre/lib/*.jar,${build.root}/${appname}/WEB-
INF/lib/*.jar,${tomcat.root}/lib/*.jar,JUnitlib/*.jar,
ANTlib/*.jar,SVNlib/*.jar,JAXBlib/*.jar,../SONARlib/*.jar" />
<property name="sonar.java.test.libraries"
value="${env.JAVA_HOME}/jre/lib/*.jar,${build.root}/${appname}/WEB-
INF/lib/*.jar,${tomcat.root}/lib/*.jar,JUnitlib/*.jar,
ANTlib/*.jar,SVNlib/*.jar,JAXBlib/*.jar,../SONARlib/*.jar" />
<property name="sonar.scm.disabled" value="false" />
<property name="sonar.scm.provider" value="svn" />
<property name="sonar.java.coveragePlugin" value="jacoco" />
<property name="sonar.jacoco.reportPath"
value="${junit.xml.exec.latest.dir}/jacoco.exec" />
<property name="sonar.junit.reportsPath"
value="${junit.xml.exec.latest.dir}" />
<sonar:sonar />
<tstamp>
<format property="sonar_endtime" pattern="dd_MM_yyyy_HH_mm" />
</tstamp>
<echo>Sonar Scan End Time:${sonar_endtime}</echo>
如果您需要更多详细信息,请与我们联系。
你能帮助为什么在声纳分析时会发生这个JaCoCo异常吗?
答案 0 :(得分:0)
在很多情况下,jacoco.exec只是没有生成。
所以我建议您检查生成失败exp的原因: