Jacoco Coverage Report not generating in correct format

1,607 views
Skip to first unread message

ankit daruka

unread,
Feb 3, 2022, 6:21:12 AM2/3/22
to JaCoCo and EclEmma Users
Hi Team,

I am using Jacoco integration with Ant in my Hybris project. It was working fine until the report was generating in exec format. But, after the sonar upgrade, exec format is deprecated and we have to move to xml report format.
 
I have made the below property changes for getting the report in xml format. The report is generated at the desired location in xml format, but the content seems to be in encoded format. Can you help me with the steps needed to migrate from exec to xml format.

Property used : 
sonar.coverage.jacoco.xmlReportPaths=hybris/log/junit/jacocoReports.xml

Please find the screenshot of the xml getting generated. Please suggest any changes required to fix the issue.

Thanks,
Ankit Daruka
JacocoReports_SS.PNG

ankit daruka

unread,
Feb 3, 2022, 7:10:55 AM2/3/22
to JaCoCo and EclEmma Users
Hi Team,

The above issue is very critical. So, need urgent help ASAP.

Thanks

Marc Hoffmann

unread,
Feb 3, 2022, 7:38:04 AM2/3/22
to JaCoCo and EclEmma Users
Hi Ankit,

what you’re showing in the screen shot is definitely not a XML file. It more looks like a binary exec file.

Please see the examples in our documentation how to create an XML report with Ant: https://www.jacoco.org/jacoco/trunk/doc/examples/build/build.xml

Best regards,
-marc

Ankit Daruka
<JacocoReports_SS.PNG>

--
You received this message because you are subscribed to the Google Groups "JaCoCo and EclEmma Users" group.
To unsubscribe from this group and stop receiving emails from it, send an email to jacoco+un...@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/jacoco/aa3efb49-d166-4a42-ab42-60dbbe537f4cn%40googlegroups.com.
<JacocoReports_SS.PNG>

ankit daruka

unread,
Feb 3, 2022, 7:44:21 AM2/3/22
to JaCoCo and EclEmma Users
Hi Marc,

Below is my build.xml file which I was using successfully for exec file format. I have only changed the file format from exec to xml in destfile attribute of below file.

<project name="jacoco_rpt_pim" xmlns:jacoco="antlib:org.jacoco.ant">
        <property name="platformhome" location="."/>
   
        <target name="jacocoalltests" description="run jacoco">    
                <ant dir="${platformhome}" target="unittests" inheritrefs="false">
                        <property name="testclasses.suppress.junit.tenant" value="true"/>
                        <property name="standalone.javaoptions" value="-javaagent:${platformhome}/lib/jacocoagent.jar=destfile=${HYBRIS_BIN_DIR}/platform/reports.xml,append=false,excludes=com.google.*:com.sun.*:de.hybris.platform.*" />                </ant>
        </target>
</project>

I am using the below command for running the jacocoalltests target
Command: ant -buildfile build.xml jacocoalltests -Dtestclasses.extensions=${unitTestExtensions}

Can you suggest what other changes are required to get the correct xml file.

Thanks

Marc Hoffmann

unread,
Feb 3, 2022, 7:49:35 AM2/3/22
to JaCoCo and EclEmma Users
Hi Ankit,

this is not the way how it works. The agent always creates exec files, even if you name them “xml”.

To create a xml report you need to run the report task. Please read the documentation.

Regards,
-marc

ankit daruka

unread,
Feb 3, 2022, 11:23:38 AM2/3/22
to JaCoCo and EclEmma Users
Hi Marc,

I analyzed the documentation and corrected my build.xml. But, I am still getting the below error. Can you please check and let me know what am I doing wrong here.

Build.xml file snippet:

<project name="jacoco_rpt_pim" xmlns:jacoco="antlib:org.jacoco.ant">
        <property name="platformhome" location="."/>
        <property name="src.dir" location="./../custom/bestprice"/>
<property name="result.dir" location="."/>
<property name="result.classes.dir" location="${result.dir}/classes"/>
<property name="result.report.dir" location="${result.dir}/site/jacoco        "/>
<property name="result.exec.file" location="${result.dir}/jacoco.exec"/>
    <taskdef uri="antlib:org.jacoco.ant" resource="org/jacoco/ant/antlib.xml">
<classpath path="${platformhome}/lib/jacocoant.jar"/>
</taskdef>

        <target name="jacocoalltests" description="run jacoco">    
                <ant dir="${platformhome}" target="unittests" inheritrefs="false">
                        <property name="testclasses.suppress.junit.tenant" value="true"/>
                        <property name="standalone.javaoptions" value="-javaagent:${platformhome}/lib/jacocoagent.jar=destfile=jacoco.exec,append=false,excludes=com.google.*:com.sun.*:de.hybris.platform.*" />                </ant>
        </target>
    
<target name="report" depends="jacocoalltests">
<!--  Step 3: Create coverage report  -->
<jacoco:report>
<!--  This task needs the collected execution data and ...  -->
<executiondata>
<file file="${result.exec.file}"/>
</executiondata>
<!--  the class files and optional source files ...  -->
<structure name="JaCoCo Ant Example">
<classfiles>
<fileset dir="${result.classes.dir}"/>
</classfiles>
<sourcefiles encoding="UTF-8">
<fileset dir="${src.dir}"/>
</sourcefiles>
</structure>
<!--  to produce reports in different formats.  -->
<html destdir="${result.report.dir}"/>
<csv destfile="${result.report.dir}/report.csv"/>
<xml destfile="${result.report.dir}/report.xml"/>
</jacoco:report>
</target>
<target name="rebuild" depends="clean,compile,test,report"/>
</project>

Command: ant  -buildfile build.xml report -Dtestclasses.extensions=${unitTetsExtensions}

Error msg:
     [echo] Report generated to C:\Hybris\CX1905PL13\hybris\log/junit/index.html
     [echo] JUNITTESTS FAILED. See C:\Hybris\CX1905PL13\hybris\log/junit/index.html!
      [ant] Exiting C:\Hybris\CX1905PL13\hybris\bin\platform\build.xml.

report:
[antlib:org.jacoco.ant] Could not load definitions from resource org/jacoco/ant/antlib.xml. It could not be found.
[jacoco:report] Loading execution data file C:\Hybris\CX1905PL13\hybris\bin\platform\jacoco.exec

BUILD FAILED
C:\Hybris\CX1905PL13\hybris\bin\platform\jacoco.xml:40: Error while creating report
        at org.jacoco.ant.ReportTask.execute(ReportTask.java:502)
        at org.apache.tools.ant.UnknownElement.execute(UnknownElement.java:292)
        at jdk.internal.reflect.GeneratedMethodAccessor4.invoke(Unknown Source)
        at java.base/jdk.internal.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
        at java.base/java.lang.reflect.Method.invoke(Method.java:566)
        at org.apache.tools.ant.dispatch.DispatchUtils.execute(DispatchUtils.java:99)
        at org.apache.tools.ant.Task.perform(Task.java:350)
        at org.apache.tools.ant.Target.execute(Target.java:449)
        at org.apache.tools.ant.Target.performTasks(Target.java:470)
        at org.apache.tools.ant.Project.executeSortedTargets(Project.java:1388)
        at org.apache.tools.ant.Project.executeTarget(Project.java:1361)
        at org.apache.tools.ant.helper.DefaultExecutor.executeTargets(DefaultExecutor.java:41)
        at org.apache.tools.ant.Project.executeTargets(Project.java:1251)
        at org.apache.tools.ant.Main.runBuild(Main.java:834)
        at org.apache.tools.ant.Main.startAnt(Main.java:223)
        at org.apache.tools.ant.launch.Launcher.run(Launcher.java:284)
        at org.apache.tools.ant.launch.Launcher.main(Launcher.java:101)
Caused by: java.io.IOException: Can't create directory C:\Hybris\CX1905PL13\hybris\bin\platform\site\jacoco \jacoco-resources.
        at org.jacoco.report.FileMultiReportOutput.createFile(FileMultiReportOutput.java:46)
        at org.jacoco.report.internal.ReportOutputFolder.createFile(ReportOutputFolder.java:92)
        at org.jacoco.report.internal.html.resources.Resources.copyResource(Resources.java:127)
        at org.jacoco.report.internal.html.resources.Resources.copyResources(Resources.java:103)
        at org.jacoco.report.html.HTMLFormatter.createVisitor(HTMLFormatter.java:192)
        at org.jacoco.ant.ReportTask$HTMLFormatterElement.createVisitor(ReportTask.java:254)
        at org.jacoco.ant.ReportTask.createVisitor(ReportTask.java:533)
        at org.jacoco.ant.ReportTask.execute(ReportTask.java:493)
        ... 16 more

Thanks,
Ankit

Marc Hoffmann

unread,
Feb 3, 2022, 3:15:19 PM2/3/22
to JaCoCo and EclEmma Users
Hi Ankit,

have a look in the error message:

Caused by: java.io.IOException: Can't create directory C:\Hybris\CX1905PL13\hybris\bin\platform\site\jacoco \jacoco-resources.

Do you notice the suspicious blank in the path? Probably that’s why the folder cannot be created.

Now look at your code:

<property name="result.report.dir" location="${result.dir}/site/jacoco        "/>

Maybe remove that extra blanks in the location attribute?

Please understand that we cannot provide general development support here. You better find someone in your organisation who can help you with Ant build basics.

Thanks for your understanding,
-marc



ankit daruka

unread,
Feb 7, 2022, 2:35:57 AM2/7/22
to JaCoCo and EclEmma Users
Hi Marc,

I am able to successfully generate the coverage report for one package/module. But, I am getting error when I am trying it for multiple modules. Below is the sample build.xml file. Can you please help on this or provide the documentation for the ant multi module report generation.

Build.xml (Single module) - Running successfully
<project name="jacoco_rpt_pim" xmlns:jacoco="antlib:org.jacoco.ant">
        <property name="platformhome" location="."/>
        <property name="src.dir" location="./../custom/bestprice"/>
<property name="result.dir" location="."/>
<property name="result.report.dir" location="${result.dir}/site/jacoco"/>
<property name="result.exec.file" location="${result.dir}/jacoco.exec"/>
    <taskdef uri="antlib:org.jacoco.ant" resource="org/jacoco/ant/antlib.xml">
<classpath path="${platformhome}/lib/jacocoant.jar"/>
</taskdef>
        <target name="jacocoalltests" description="run jacoco">    
                <ant dir="${platformhome}" target="unittests" inheritrefs="false">
                        <property name="testclasses.suppress.junit.tenant" value="true"/>
                        <property name="standalone.javaoptions" value="-javaagent:${platformhome}/lib/jacocoagent.jar=destfile=jacoco.exec,append=true,excludes=com.google.*:com.sun.*:de.hybris.platform.*" />                </ant>

        </target>
       
<target name="report" depends="jacocoalltests">
<!--  Step 3: Create coverage report  -->
<jacoco:report>
<!--  This task needs the collected execution data and ...  -->
<executiondata>
<file file="${result.exec.file}"/>
</executiondata>
<!--  the class files and optional source files ...  -->
<structure name="JaCoCo Ant Example">
 <classfiles>
<fileset dir="./../custom/bestprice/bestpricepayments/classes"/>
</classfiles>


</structure>
<!--  to produce reports in different formats.  -->
<html destdir="${result.report.dir}"/>
<xml destfile="${result.report.dir}/report.xml"/>
</jacoco:report>
</target>
</project>

Build.xml(multi module) - Below both are Failing

<jacoco:report>
<!--  This task needs the collected execution data and ...  -->
<executiondata>
<file file="${result.exec.file}"/>
</executiondata>
<!--  the class files and optional source files ...  -->
<structure name="JaCoCo Ant Example">
 <classfiles>
<fileset dir="./../custom/bestprice/bestpricepayments/classes"/>
</classfiles>
<classfiles>
<fileset dir="./../custom/bestprice/bestpricecore/classes"/>
</classfiles>

</structure>
<!--  to produce reports in different formats.  -->
<html destdir="${result.report.dir}"/>
<xml destfile="${result.report.dir}/report.xml"/>
</jacoco:report>

OR This

<!--  Step 3: Create coverage report  -->
<jacoco:report>
<!--  This task needs the collected execution data and ...  -->
<executiondata>
<file file="${result.exec.file}"/>
</executiondata>
<!--  the class files and optional source files ...  -->
<structure name="JaCoCo Ant Example">

 <group name="Core">
        <classfiles>
            <fileset dir="./../custom/bestprice/bestpricecore/classes"/>
        </classfiles>
     
    </group>
    <group name="Payment">
        <classfiles>
            <fileset dir="./../custom/bestprice/bestpricepayments/classes"/>
        </classfiles>
     
    </group>

</structure>
<!--  to produce reports in different formats.  -->
<html destdir="${result.report.dir}"/>
<xml destfile="${result.report.dir}/report.xml"/>
</jacoco:report>

Thanks,
Ankit Daruka

Marc Hoffmann

unread,
Feb 7, 2022, 2:49:41 AM2/7/22
to JaCoCo and EclEmma Users
Hi Ankit,

if you just say "I am getting error” probably no one can guess what your problem is. Please provide the full error message including stack trace if available.

Regards,
-marc

ankit daruka

unread,
Feb 7, 2022, 3:35:40 AM2/7/22
to JaCoCo and EclEmma Users
Hi Marc,

Please find below the error message:

[yunitint] Tests FAILED
 [yunitrep] Processing C:\Hybris\CX1905PL13\hybris\log\junit\TESTS-TestSuites.xml to C:\Users\DEV-VN~1\AppData\Local\Temp\null1393824659
 [yunitrep] Loading stylesheet jar:file:/C:/Hybris/CX1905PL13/hybris/bin/platform/apache-ant/lib/ant-junit.jar!/org/apache/tools/ant/taskdefs/optional/junit/xsl/junit-frames.xsl
 [yunitrep] Transform time: 1386ms
 [yunitrep] Deleting: C:\Users\DEV-VN~1\AppData\Local\Temp\null1393824659

     [echo] Report generated to C:\Hybris\CX1905PL13\hybris\log/junit/index.html
     [echo] JUNITTESTS FAILED. See C:\Hybris\CX1905PL13\hybris\log/junit/index.html!

report:

[jacoco:report] Loading execution data file C:\Hybris\CX1905PL13\hybris\bin\platform\jacoco.exec
[jacoco:report] Writing bundle 'Core' with 990 classes
[jacoco:report] Classes in bundle 'Core' do not match with execution data. For report generation the same class files must be used as at runtime.
[jacoco:report] Execution data for class com/bestprice/core/cache/listener/InvalidateMessageItemCacheEventListenerTest does not match.
[jacoco:report] Execution data for class com/bestprice/core/strategies/impl/BestpriceWindowsAzureBlobStorageStrategyTest does not match.
[jacoco:report] Execution data for class com/bestprice/core/dao/impl/DefaultBestpriceCouponDaoTest does not match.
[jacoco:report] Execution data for class com/bestprice/core/services/impl/DefaultBestpriceInvoiceGatewayService does not match.
[jacoco:report] Execution data for class com/bestprice/core/job/BestpriceGPNotificationCronJobTest does not match.
[jacoco:report] Execution data for class com/bestprice/core/util/MemberValidationUtilsTest does not match.
[jacoco:report] Execution data for class com/bestprice/core/util/BestpriceCouponUtils does not match.
[jacoco:report] Execution data for class com/bestprice/core/payment/impl/DefaultBestpriceLedgerBalancePaymentServiceTest does not match.
[jacoco:report] Execution data for class com/bestprice/core/job/BestpricePromotionEnrichmentReportJobTest does not match.
[jacoco:report] Execution data for class com/bestprice/core/util/MccSiteUrlHelperTest does not match.
[jacoco:report] Execution data for class com/bestprice/core/order/impl/DefaultBestpriceCommercePlaceOrderStrategyTest does not match.
[jacoco:report] Execution data for class com/bestprice/core/services/impl/BestpriceCoreDataImportServiceTest does not match.
[jacoco:report] Execution data for class com/bestprice/core/job/BestPriceBackInStockCombinedCronJobTest does not match.
[jacoco:report] Execution data for class com/bestprice/core/services/impl/DefaultBestpriceInvoiceGatewayServiceTest does not match.
[jacoco:report] Execution data for class com/bestprice/core/strategies/DefaultBestpriceSingleCodeCouponRedemptionStrategyTest does not match.
[jacoco:report] Execution data for class com/bestprice/core/services/impl/DefaultBestpriceAzureBlobIntegrationServiceTest does not match.
[jacoco:report] Execution data for class com/bestprice/core/util/BestpriceCouponUtilsTest does not match.
[jacoco:report] Execution data for class com/bestprice/core/stock/impl/DefaultBestpriceStockAvailabilityServiceTest does not match.
[jacoco:report] Execution data for class com/bestprice/core/strategies/impl/DefaultBestpriceQuoteCreationStrategyTest does not match.
[jacoco:report] Execution data for class com/bestprice/core/payment/impl/DefaultBestpriceLedgerBalancePaymentService does not match.
[jacoco:report] Execution data for class com/bestprice/core/component/slot/impl/DefaultBestpriceCMSPageSlotComponentServiceTest does not match.
[jacoco:report] Execution data for class com/bestprice/core/services/impl/DefaultBestpriceFreightServiceTest does not match.
[jacoco:report] Execution data for class com/bestprice/core/job/BestpricePromotionEnrichmentReportJob does not match.
[jacoco:report] Execution data for class com/bestprice/core/cache/listener/SolrCacheEventListenerTest does not match.
[jacoco:report] Execution data for class com/bestprice/core/job/BestPriceBackInStockCronJobTest does not match.
[jacoco:report] Execution data for class com/bestprice/core/stock/impl/DefaultBestpriceStockAvailabilityService does not match.
[jacoco:report] Writing bundle 'Payment' with 157 classes

BUILD FAILED
Target "bestpricecore" does not exist in the project "jacoco_rpt_pim".

Thanks,
Ankit Daruka

Marc Hoffmann

unread,
Feb 7, 2022, 3:40:48 AM2/7/22
to JaCoCo and EclEmma Users
> BUILD FAILED
> Target "bestpricecore" does not exist in the project "jacoco_rpt_pim".

Looks like a plain Ant issue, not related to JaCoCo at all.

Please understand that we cannot provide general programming support here for free. As suggested before you better find someone in your organisation with basic Ant build knowledge.

Regards,
-marc



ankit daruka

unread,
Feb 7, 2022, 3:50:09 AM2/7/22
to JaCoCo and EclEmma Users
Hi Marc,

Can you please provide the ant multi module documentation for jacoco so that I can refer. The above error is only coming if I am using multi module otherwise its running fine.

Thanks,
Ankit Daruka

Reply all
Reply to author
Forward
0 new messages