1,ant下載,解壓 ,環(huán)境配置;
官網(wǎng):https://ant.apache.org/
配置:
export ANT_HOME=/Users/xxx/apache-ant-1.10.8
export PATH=${PATH}:${ANT_HOME}/bin
2,jacoco下載,解壓
官網(wǎng):https://www.eclemma.org/jacoco/
解壓后,lib文件加找出jacocoant.jar,復制到ant環(huán)境lib包里
3,build.xml
文件放在ant環(huán)境bin包里
<?xml version="1.0" ?>
<?xml version="1.0" ?>
<project name="testExec" xmlns:jacoco="antlib:org.jacoco.ant" default="report">
? ? ? ? <property name="test.server.host" value="127.0.0.1" />
? ? ? ? <property name="local.server.host" value="127.0.0.1" />
? ? ? ? <property name="sangClasspath" value="/Users/pengbo.zi/IdeaProjects/VBlog/blogserver/target/classes" />?
? ? ? ? <property name="sangSourcepath" value="/Users/pengbo.zi/IdeaProjects/VBlog/blogserver/src/main/java" />?
? ? ? ? <property name="reportfolderPath" value="/Users/pengbo.zi/JaCoCo_report" />
? ? ? ? <!--讓ant知道去哪兒找Jacoco-->
? ? ? ? <taskdef uri="antlib:org.jacoco.ant" resource="org/jacoco/ant/antlib.xml">
? ? ? ? ? ? ? ? <!-- 本地jacocoant.jar路徑 -->
? ? ? ? ? ? ? ? <classpath path="/Users/pengbo.zi/apache-ant-1.10.8/lib/jacocoant.jar" />
? ? ? ? </taskdef>?
? ? ? ? <target name="clean">
? ? ? ? ? ? ? ? <!-- 清空文件 -->
? ? ? ? ? ? ? ? <delete dir="/Users/pengbo.zi/jacoco_data/report" />
? ? ? ? ? ? ? ? <delete dir="/Users/pengbo.zi/jacoco_data/exec" />
? ? ? ? </target>
? ? ? ? <target name="dump">
? ? ? ? ? ? ? ? ? <jacoco:dump address="${test.server.host}" reset="false" destfile="/Users/pengbo.zi/jacoco_data/jacoco_dump.exec" port="9527" append="true"/>
? ? ? ? </target>
? ? ? ? <target name="merge">
? ? ? ? ? ? ? ? <!-- 合并多份exec文件 -->
? ? ? ? ? ? ? ? <delete dir="/Users/pengbo.zi/jacoco_data/exec" />
? ? ? ? ? ? ? ? <mkdir dir="/Users/pengbo.zi/jacoco_data/exec" />
? ? ? ? ? ? ? ? <jacoco:merge destfile="/Users/pengbo.zi/jacoco_data/exec/merged.exec">
? ? ? ? ? ? ? ? ? ? ? ? <fileset dir="/Users/pengbo.zi/jacoco_data/" includes="*.exec" />
? ? ? ? ? ? ? ? </jacoco:merge>
? ? ? ? </target>
? ? ? ? <target name="report" depends="dump,merge">
? ? ? ? ? ? <!--? Step 3: Create coverage report? -->
? ? ? ? ? ? <delete dir="${reportfolderPath}" />
? ? ? ? ? ? <mkdir dir="${reportfolderPath}" />
? ? ? ? ? ? <jacoco:report>
? ? ? ? ? ? ? ? <!--
? ? ? ? ? ? ? ? This task needs the collected execution data and ...
? ? ? ? ? ? ? ? -->
? ? ? ? ? ? ? ? <executiondata>
? ? ? ? ? ? ? ? ? ? <file file="/Users/pengbo.zi/jacoco_data/exec/merged.exec"/>
? ? ? ? ? ? ? ? </executiondata>
? ? ? ? ? ? ? ? <!--? the class files and optional source files ...? -->
? ? ? ? ? ? ? ? <structure name="JaCoCo Report">
? ? ? ? ? ? ? ? ? ? <group name="sang_related">
? ? ? ? ? ? ? ? ? ? ? <sourcefiles encoding="UTF-8">
? ? ? ? ? ? ? ? ? ? ? ? <fileset dir="${sangSourcepath}"/>
? ? ? ? ? ? ? ? ? ? ? </sourcefiles>
? ? ? ? ? ? ? ? ? ? ? <classfiles>
? ? ? ? ? ? ? ? ? ? ? ? <fileset dir="${sangClasspath}"/>
? ? ? ? ? ? ? ? ? ? ? </classfiles>
? ? ? ? ? ? ? ? ? ? </group>
? ? ? ? ? ? ? ? </structure>
? ? ? ? ? ? ? ? <!--? 生成html報告文件地址? -->
? ? ? ? ? ? ? ? <html destdir="${reportfolderPath}/report" encoding="utf-8"/>
? ? ? ? ? ? ? ? <csv destfile="${reportfolderPath}/report.csv"? />
? ? ? ? ? ? ? ? <xml destfile="${reportfolderPath}/report.xml" />
? ? ? ? ? ? </jacoco:report>
? ? ? ? </target>
</project>
4,項目啟動
java?-javaagent:/Users/xxx/jacoco-0.8.5/lib/jacocoagent.jar=includes=xxx.*,output=tcpserver,port=9527,address=127.0.0.1? -jar /Users/xxx/java-project/xxx.jar? -Xverify:none?
5, ant命令
ant dump,ant merge,ant report;
參考:https://blog.csdn.net/qq_26392615/article/details/82228972?