<!-- ========= Sonar分析客戶端 ========= -->
<target name="sonar" depends="sonar.compile">
<taskdef uri="antlib:org.sonar.ant" resource="org/sonar/ant/antlib.xml">
<classpath path="${sonar.lib.dir}/sonar-ant-task-2.0.jar" />
</taskdef>
<!-- 執(zhí)行 Sonar -->
<sonar:sonar key="${sonar.projectKey}" version="1.0" xmlns:sonar="antlib:org.sonar.ant"/>
</target>
3) 直接運(yùn)行ant build或者在命令行輸入ant sonar可以分析Java工程,結(jié)束后上傳數(shù)據(jù)至指定sonar網(wǎng)站。
四)加入單元測(cè)試統(tǒng)計(jì)
<!-- JaCoCo相關(guān)配置: -->
<property name="sonar.dynamicAnalysis" value="reuseReports" />
<property name="sonar.java.coveragePlugin" value="jacoco" />
<property name="sonar.jacoco.reportPath" value="target/jacoco.exec" />
<!-- testng定義: -->
<taskdef name="testng" classname="com.beust.testng.TestNGAntTask">
<classpath>
<path refid="sonar.classpath"/>
</classpath>
</taskdef>
<!-- 引入 JaCoCo Ant Task -->
<taskdef uri="antlib:org.jacoco.ant" resource="org/jacoco/ant/antlib.xml">
<classpath path="${sonar.lib.dir}/jacocoant.jar" />
</taskdef>
<!-- 運(yùn)行單元測(cè)試, 添加 JaCoCo agent -->
<jacoco:coverage destfile="target/jacoco.exec" xmlns:jacoco="antlib:org.jacoco.ant">
<testng outputDir="${testng.report.dir}" classpathref="sonar.runpath" excludedgroups="${EX}">
<xmlfileset dir="${test.resources.dir}" includes="testng.xml"/>
<jvmarg value="-Dtest.resources.dir=${test.resources.dir}" />
</testng>
</jacoco:coverage>
</target>
<!-- ========= Sonar分析客戶端 ========= -->
<target name="sonar" depends="sonar.compile">
<taskdef uri="antlib:org.sonar.ant" resource="org/sonar/ant/antlib.xml">
<classpath path="${sonar.lib.dir}/sonar-ant-task-2.0.jar" />
</taskdef>
<!-- 執(zhí)行 Sonar -->
<sonar:sonar key="${sonar.projectKey}" version="1.0" xmlns:sonar="antlib:org.sonar.ant"/>
</target>