Jacoco coverage with sonarqube 8.9 using ant

Hi Community, I’ve faced issue on SonarQube 8.9 after sonar task finished I still see 0% test coverage on project. My configuration:

properties
sonar.coverage.jacoco.xmlReportPaths=target/site/jacoco/jacoco.xml

xml:


<taskdef uri="antlib:org.sonar.ant" resource="org/sonar/ant/antlib.xml">
        <classpath>
            <path path="${platformhome}/resources/ant/sonar/lib/sonarqube-ant-task-2.7.0.1612.jar"/>
        </classpath>
    </taskdef>

<taskdef uri="antlib:org.jacoco.ant" resource="org/jacoco/ant/antlib.xml">
        <classpath>
            <path path="${platformhome}/resources/ant/sonar/lib/jacocoant.jar"/>
        </classpath>
    </taskdef>

//here is part of my sonar macrodef
<macrodef name="sonarcheck">
<sequential>
<sequential>
            <jacoco:report>
                <structure name="Test">
                    <group name="General">
                        <classfiles>
                            <fileset dir="${HYBRIS_BIN_DIR}">
                                <include name="**/*.class"/>
                            </fileset>
                        </classfiles>
                        <sourcefiles>
                            <fileset dir="${HYBRIS_BIN_DIR}">
                                <include name="**/*.java"/>
                            </fileset>
                        </sourcefiles>
                    </group>
                </structure>
            </jacoco:report>
            </sequential>
          <sonar:sonar/>
        </sequential>
</macrodef>

sonar report works fine, but jacoco code coverage show 0%
before SonarQube 8.9 I just had one property : sonar.jacoco.reportPath=${HYBRIS_LOG_DIR}/jacoco/jacoco.exec
even without jacoco:report/ task in my sonar.xml file, and coverage was calculated and displayed in sonar. Does anybody have ideas what I could probably missed?

Hi,

You’re showing a property defining the path to the XML report. Are you setting that property in your Ant file? And what does your analysis log say about this?

 
Ann

Hi @ganncamp Yes, I’m adding this property to sonar task during execution:

ant -Dsonar.host.url=${hostUrl} " +
                "-Dsonar.login=${token} " +
                "-Dsonar.branch.name=${source_branch} " +
                "-Dsonar.pullrequest.branch=${source_branch} " +
                "-Dsonar.pullrequest.base=${target_branch} " +
                "-Dsonar.projectBaseDir=${env.workspace} " +
                "-Dsonar.projectKey=${projKey} " +
                "-Dsonar.coverage.jacoco.xmlReportPaths=${jacocoPath} sonarcheck -v

Hi,

I’m not familiar with passing parameters on the Ant command line. Are these parameters really translated into Ant properties?

And if so, can you post your analysis log?

 
Ann