Механизм покрытия кода JaCoCo в Jenkins с помощью Sonar

Мне нужно настроить механизм покрытия кода JaCoCo в Jenkins с помощью Sonar.

Я сделал следующие записи в файле 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-покрытия», поэтому цель «jacoco-report» не выполняется.

Любой ввод, указатель будет оценен.

Заранее спасибо.


person sagar borse    schedule 09.10.2012    source источник


Ответы (2)


Посмотрите наш образец проекта здесь: https://github.com/SonarSource/sonar-examples/tree/master/projects/code-coverage/ut/ant/ut-ant-jacoco-reuseReports

Это должно вам помочь.

person Fabrice - SonarSource Team    schedule 09.10.2012
comment
Мой тестовый пример работает нормально, но он не создает выходной файл jacoco.exec. Следовательно, невозможно перейти к созданию отчета. - person sagar borse; 09.10.2012
comment
Мне пришлось переформировать путь к классам из примера, чтобы он работал правильно. - person ingyhere; 08.06.2013

У меня работают следующие настройки без каких-либо свойств:

<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>
person openCage    schedule 20.06.2014