Hello All,
I am also getting same issue
Generating code coverage with Ant and Jacoco.
In my project we are using Ant, Sonar and Gitlab CI/CD pipelines. I am new to Ant buidl.xml
Can any one help me to fix the issue
build.xml file contains
<?xml version="1.0"?>
<project name="Agile" xmlns:jacoco="antlib:org.jacoco.ant" default="test" basedir="." xmlns:if="ant:if" xmlns:unless="ant:unless">
<property file="Buildinputs.properties"/>
<property name="srcdir" value="${basedir}" />
<property name="lib.dir" value="${basedir}/lib" />
<property name="war.dir" value="${DestinationPath}/Wars" />
<property name="jar.dir" value="${DestinationPath}/Jars" />
<property name="jacoco.jar" location="../monet-main/lib/dev/sonar/jacocoant.jar" />
<!--taskdef uri="antlib:org.jacoco.ant" resource="org/jacoco/ant/antlib.xml">
<classpath>
<pathelement location="${basedir}/commonlib/antcontrib.jar"/>
<pathelement location="${jacocoant.jar}"/>
</classpath>
</taskdef>-->
<path id="compile-test.classpath">
<pathelement location="./lib/junit-4.12.jar" />
<pathelement location="./lib/hamcrest-core-1.3.jar" />
<pathelement location="./lib/org.jacoco.ant-0.7.2.201409121644.jar"/>
<pathelement location="./lib/ant-contrib-1.0b3.jar" />
<pathelement location="target/classes"/>
</path>
<taskdef uri="antlib:org.jacoco.ant" resource="org/jacoco/ant/antlib.xml">
<classpath refid="compile-test.classpath" />
<classpath path="lib/test/org.jacoco.ant.jar"/>
</taskdef>
<taskdef name="jacoco-coverage" classname="org.jacoco.ant.CoverageTask" />
<taskdef name="jacoco-report" classname="org.jacoco.ant.ReportTask" />
<taskdef name="findbugs" classname="edu.umd.cs.findings.anttask.FindBugsTask" />
<property environment="env" />
<tstamp prefix="build-info">
<format property="current-date" pattern="d-MMMM-yyyy" locale="en" />
<format property="current-time" pattern="hh:mm:ss a z" locale="en" />
</tstamp>
<path id="compileJar.path">
<fileset dir="${basedir}/lib">
<include name="*.jar"/>
<include name="*.zip"/>
</fileset>
<fileset dir="${basedir}/commonlib">
<include name="*.jar"/>
<include name="*.zip"/>
</fileset>
</path>
<target name="jar" depends="compile">
<antcall target="compile">
<param name="Service_Name" value="${Service_Name}"/>
<param name="Artifact_Type" value="jar"/>
</antcall>
<jar destfile="${jar.dir}/${Jar_Name}" >
<fileset dir="src"/>
<manifest>
<attribute name="Built-Copyright" value="${build-copyright-info}"/>
<attribute name="Built-By" value="${user.name}" />
<attribute name="Built-On" value="${build-info.current-date}" />
<attribute name="Built-Time" value="${build-info.current-time}" />
<attribute name="Build-Number" value="${env.BUILD_BUILDNUMBER}" />
</manifest>
</jar>
<!--<zip destfile="${DestinationPath}/${Service_Name}.zip" basedir="${jar.dir}" update="true" />-->
<echo message="**************JAR created successfully : ${Service_Name}**************" />
</target>
<target name="clean">
<delete dir="target"/>
<delete dir="${build.dir}" />
</target>
<!-- Create target folder>-->
<target name="prepare" depends="clean">
<mkdir dir="target/classes"/>
<mkdir dir="target/test-classes"/>
<copy includeemptydirs="false" todir="target/classes">
<fileset dir="src/main/java">
<exclude name="**/*.java"/>
</fileset>
</copy>
<copy includeemptydirs="false" todir="target/test-classes">
<fileset dir="src/test/java">
<exclude name="**/*.java"/>
</fileset>
</copy>
</target>
<target name="compile" depends="prepare">
<javac srcdir="." destdir="target/test-classes" debug="true" includeantruntime="false" classpathref="compileJar.path" />
</target>
<target name="test" depends="jar">
<jacoco:coverage destfile="target/" xmlns:jacoco="antlib:org.jacoco.ant" exclclassloader="sun.reflect.DelegatingClassLoader:javassist.Loader" >
<junit haltonfailure="false" printsummary="true" fork="on" forkmode="once">
<formatter type="brief" usefile="false"/>
<test name="com.valdimessage.fix44.AccountSetupStrategyTest" filtertrace="true" />
<batchtest>
<fileset dir="target/test-classes">
<include name="**/*Test*" />
</fileset>
</batchtest>
<classpath>
<pathelement location="target/test-classes"/>
<path refid="compile-test.classpath" />
</classpath>
</junit>
</jacoco:coverage>
<echo message="Generating Jacoco reports..." />
<jacoco:report xmlns:jacoco="antlib:org.jacoco.ant">
<executiondata>
<file file="target/jacoco.exec"/>
</executiondata>
<structure name="jacoco-report">
<classfiles>
<fileset dir="target/classes"/>
</classfiles>
<sourcefiles encoding="UTF-8">
<fileset dir="src/main/java"/>
</sourcefiles>
</structure>
<html destdir="target/coverage-report"/>
<xml destfile="target/coverage-report/report.xml"/>
</jacoco:report>
</target>
</project>
------------------------------
Error Details.
Buildfile: /builds/[MASKED]/Build.xml
[2014](
https://gitlab.dell.com/Subhash_Mannem/createandsaveaseventspx/-/jobs/48975411#L2014) [taskdef] Could not load definitions from resource org/jacoco/ant/antlib.xml. It could not be found.
[2015](
https://gitlab.dell.com/Subhash_Mannem/createandsaveaseventspx/-/jobs/48975411#L2015)BUILD FAILED
[2016](
https://gitlab.dell.com/Subhash_Mannem/createandsaveaseventspx/-/jobs/48975411#L2016)/builds/[MASKED]/Build.xml:28: taskdef class org.jacoco.ant.CoverageTask cannot be found
[2017](
https://gitlab.dell.com/Subhash_Mannem/createandsaveaseventspx/-/jobs/48975411#L2017) using the classloader AntClassLoader[]
[2018](
https://gitlab.dell.com/Subhash_Mannem/createandsaveaseventspx/-/jobs/48975411#L2018)Total time: 0 seconds
[2020](
https://gitlab.dell.com/Subhash_Mannem/createandsaveaseventspx/-/jobs/48975411#L2020)Uploading artifacts for failed job00:00
[2021](
https://gitlab.dell.com/Subhash_Mannem/createandsaveaseventspx/-/jobs/48975411#L2021)Uploading artifacts...
[2022](
https://gitlab.dell.com/Subhash_Mannem/createandsaveaseventspx/-/jobs/48975411#L2022)WARNING: target/*: no matching files
[2023](
https://gitlab.dell.com/Subhash_Mannem/createandsaveaseventspx/-/jobs/48975411#L2023)ERROR: No files to upload
[2025](
https://gitlab.dell.com/Subhash_Mannem/createandsaveaseventspx/-/jobs/48975411#L2025)Cleaning up file based variables00:00
[2027](
https://gitlab.dell.com/Subhash_Mannem/createandsaveaseventspx/-/jobs/48975411#L2027)ERROR: Job failed: command terminated with exit code 1