1<?xml version="1.0" encoding="UTF-8"?> 2 3<!-- 4 Copyright (c) 2009, 2021 Mountainminds GmbH & Co. KG and Contributors 5 This program and the accompanying materials are made available under 6 the terms of the Eclipse Public License 2.0 which is available at 7 http://www.eclipse.org/legal/epl-2.0 8 9 SPDX-License-Identifier: EPL-2.0 10 11 Contributors: 12 Marc R. Hoffmann - initial API and implementation 13--> 14 15<project name="Example Ant Build with JaCoCo" default="rebuild" xmlns:jacoco="antlib:org.jacoco.ant"> 16 17 <description> 18 Example Ant build file that demonstrates how a JaCoCo coverage report 19 can be itegrated into an existing build in three simple steps. 20 </description> 21 22 <property name="src.dir" location="./src/main/java" /> 23 <property name="result.dir" location="./target" /> 24 <property name="result.classes.dir" location="${result.dir}/classes" /> 25 <property name="result.report.dir" location="${result.dir}/site/jacoco" /> 26 <property name="result.exec.file" location="${result.dir}/jacoco.exec" /> 27 28 <!-- Step 1: Import JaCoCo Ant tasks --> 29 <taskdef uri="antlib:org.jacoco.ant" resource="org/jacoco/ant/antlib.xml"> 30 <classpath path="../../../lib/jacocoant.jar" /> 31 </taskdef> 32 33 <target name="clean"> 34 <delete dir="${result.dir}" /> 35 </target> 36 37 <target name="compile"> 38 <mkdir dir="${result.classes.dir}" /> 39 <javac srcdir="${src.dir}" destdir="${result.classes.dir}" debug="true" includeantruntime="false" /> 40 </target> 41 42 <target name="test" depends="compile"> 43 <!-- Step 2: Wrap test execution with the JaCoCo coverage task --> 44 <jacoco:coverage destfile="${result.exec.file}"> 45 <java classname="org.jacoco.examples.parser.Main" fork="true"> 46 <classpath path="${result.classes.dir}" /> 47 <arg value="2 * 3 + 4"/> 48 <arg value="2 + 3 * 4"/> 49 <arg value="(2 + 3) * 4"/> 50 <arg value="2 * 2 * 2 * 2"/> 51 <arg value="1 + 2 + 3 + 4"/> 52 <arg value="2 * 3 + 2 * 5"/> 53 </java> 54 </jacoco:coverage> 55 </target> 56 57 <target name="report" depends="test"> 58 <!-- Step 3: Create coverage report --> 59 <jacoco:report> 60 61 <!-- This task needs the collected execution data and ... --> 62 <executiondata> 63 <file file="${result.exec.file}" /> 64 </executiondata> 65 66 <!-- the class files and optional source files ... --> 67 <structure name="JaCoCo Ant Example"> 68 <classfiles> 69 <fileset dir="${result.classes.dir}" /> 70 </classfiles> 71 <sourcefiles encoding="UTF-8"> 72 <fileset dir="${src.dir}" /> 73 </sourcefiles> 74 </structure> 75 76 <!-- to produce reports in different formats. --> 77 <html destdir="${result.report.dir}" /> 78 <csv destfile="${result.report.dir}/report.csv" /> 79 <xml destfile="${result.report.dir}/report.xml" /> 80 </jacoco:report> 81 </target> 82 83 <target name="rebuild" depends="clean,compile,test,report" /> 84 85</project> 86