【问题标题】:JaCoCo code coverage engine in Jenkins with SonarJenkins 中的 JaCoCo 代码覆盖引擎和 Sonar
【发布时间】:2012-09-29 15:58:35
【问题描述】:

我需要在 Jenkins 中使用 Sonar 配置 JaCoCo 代码覆盖引擎。

我在 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

我还写了以下蚂蚁任务:

<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>

jacoco.exec 文件不是从“jacoco-coverage”生成的,因此“jacoco-report”目标失败。

任何输入,指针将不胜感激。

提前致谢。

【问题讨论】:

    标签: java junit jenkins sonarqube jacoco


    【解决方案1】:

    【讨论】:

    • 我的测试用例运行良好,但没有创建输出文件“jacoco.exec”。因此无法继续生成报告。
    • 我不得不重新构建示例中的类路径以使其正常工作。
    【解决方案2】:

    以下没有任何属性的设置对我有用:

    <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>
    

    【讨论】:

      猜你喜欢
      • 2012-06-11
      • 1970-01-01
      • 2016-11-08
      • 2018-07-24
      • 2014-02-16
      • 2017-05-31
      • 2013-02-07
      • 2012-10-16
      • 2018-05-31
      相关资源
      最近更新 更多