[英]JaCoCo code coverage engine in Jenkins with Sonar
I need to configure JaCoCo code coverage engine in Jenkins with Sonar. 我需要使用Sonar在Jenkins中配置JaCoCo代码覆盖引擎。
I have made the following entries in the sonar-project.properties file 我在sonar-project.properties文件中输入了以下条目
sonar.projectKey=projectX:projectX
sonar.projectName=projectX
sonar.projectVersion=1.0
sources=src
tests=test
binaries=workspace/stage/main/classes,workspace/stage/test/classes
libraries=workspace/stage/artifact/lib/*.jar
sonar.dynamicAnalysis=reuseReports
sonar.core.codeCoveragePlugin=jacoco
sonar.jacoco.reportPath=reports/jacoco.exec
I have also written the following ant tasks: 我还写了以下ant任务:
<taskdef uri="antlib:org.jacoco.ant" resource="org/jacoco/ant/antlib.xml">
</taskdef>
<target name="jacoco-coverage">
<jacoco:coverage enabled="true" destfile="jacoco.exec">
<junit fork="true" forkmode="once" includeAntRuntime="true" maxmemory="512M" printsummary="withOutAndErr" haltonfailure="false">
<test name="com.test.HelloWorld"/>
<batchtest todir="workspace/stage/test/classes/">
<fileset dir="../test" includes="**/*.java"/>
</batchtest>
<classpath>
<path refid="classpath.test"/>
<pathelement location="workspace/stage/test/classes/" />
</classpath>
</junit>
</jacoco:coverage>
</target>
<target name="jacoco-report">
<jacoco:report>
<executiondata>
<file file="jacoco.exec" />
</executiondata>
<structure name="Example Project">
<classfiles>
<fileset dir="workspace/stage/test/classes" />
</classfiles>
<sourcefiles encoding="UTF-8">
<fileset dir="test" />
</sourcefiles>
</structure>
<html destdir="report" />
</jacoco:report>
</target>
The jacoco.exec file is not getting generated from "jacoco-coverage" so the "jacoco-report" target is failing. jacoco.exec文件未从“jacoco-coverage”生成,因此“jacoco-report”目标失败。
Any input, pointer will be appreciated. 任何输入,指针将不胜感激。
Thanks in advance. 提前致谢。
Check our sample project here: https://github.com/SonarSource/sonar-examples/tree/master/projects/code-coverage/ut/ant/ut-ant-jacoco-reuseReports 在这里查看我们的示例项目: https : //github.com/SonarSource/sonar-examples/tree/master/projects/code-coverage/ut/ant/ut-ant-jacoco-reuseReports
This should help you. 这应该对你有帮助。
The following settings without any properties work for me: 没有任何属性的以下设置对我有用:
<plugins>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-failsafe-plugin</artifactId>
<configuration>
<encoding>UTF-8</encoding>
<!--write repo rts into surefire-reports dir so jacoco can pick them up-->
<reportsDirectory>${project.build.directory}/surefire reports</reportsDirectory>
<!--add jacoco-->
<argLine>${jacoco.agent.argLine}</argLine>
</configuration>
<executions>
<execution>
<goals>
<goal>integration-test</goal>
<goal>verify</goal>
</goals>
</execution>
</executions>
</plugin>
<plugin>
<groupId>org.jacoco</groupId>
<artifactId>jacoco-maven-plugin</artifactId>
<configuration>
<propertyName>jacoco.agent.argLine</propertyName> <!-- default: argLine -->
<destFile>${project.build.directory}/jacoco-integration.exec</destFile> <!-- agent -->
<dataFile>${project.build.directory}/jacoco-integration.exec</dataFile> <!-- report -->
</configuration>
<executions>
<execution>
<id>agent</id>
<goals><goal>prepare-agent</goal></goals>
</execution>
</executions>
</plugin>
</plugins>
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.