Skip to content

Instantly share code, notes, and snippets.

@swapnonil
Last active August 29, 2015 13:56
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save swapnonil/20bb884051d3a552e6ce to your computer and use it in GitHub Desktop.
Save swapnonil/20bb884051d3a552e6ce to your computer and use it in GitHub Desktop.
Ant build script with Sonar, Jacoco Integration
<?xml version="1.0" encoding="UTF-8" standalone="no"?>
<!-- WARNING: Eclipse auto-generated file.
Any modifications will be overwritten.
To include a user specific buildfile here, simply create one in the same
directory with the processing instruction <?eclipse.ant.import?>
as the first entry and export the buildfile again. -->
<project basedir="." default="build" name="SomeLegacyCode" xmlns:sonar="antlib:org.sonar.ant" xmlns:jacoco="antlib:org.jacoco.ant">
<property environment="env" />
<property name="ECLIPSE_HOME" value="../../" />
<property name="debuglevel" value="source,lines,vars" />
<property name="target" value="1.7" />
<property name="source" value="1.7" />
<property name="report.junit" value="report/junit" />
<property name="reports.jacoco.dir" value="report/jacoco" />
<property name="sonar.host.url" value="http://localhost:9000" />
<property name="sonar.jdbc.url" value="jdbc:h2:tcp://localhost:9092/sonar" />
<property name="sonar.jdbc.username" value="sonar" />
<property name="sonar.jdbc.password" value="sonar" />
<!-- Define the SonarQube project properties -->
<property name="sonar.projectKey" value="some-legacy-code" />
<property name="sonar.projectName" value="Some Legacy Code" />
<property name="sonar.projectVersion" value="1.0" />
<property name="sonar.language" value="java" />
<property name="sonar.libraries" value="lib/*.jar" />
<property name="sonar.sources" value="src" />
<property name="sonar.binaries" value="bin" />
<property name="sonar.tests" value="tests" />
<property name="sonar.verbose" value="true" />
<property name="sonar.core.codeCoveragePlugin" value="jacoco" />
<property name="sonar.jacoco.reportPath" value="${reports.jacoco.dir}/jacoco.exec" />
<path id="libraries.path">
<!-- Include compiles classes -->
<pathelement location="bin" />
<!-- Include all jar files located in lib directory -->
<fileset dir="lib">
<include name="**/*.jar" />
</fileset>
</path>
<!-- Init -->
<target name="init">
<mkdir dir="bin" />
<copy includeemptydirs="false" todir="bin">
<fileset dir="src">
<exclude name="**/*.java" />
</fileset>
</copy>
</target>
<!-- Clean -->
<target name="clean">
<delete dir="bin" />
</target>
<!-- Compile -->
<target depends="init" name="build">
<echo message="${ant.project.name}: ${ant.file}" />
<javac debug="true" debuglevel="${debuglevel}" destdir="bin" includeantruntime="false" source="${source}" target="${target}">
<src path="src" />
<src path="tests" />
<classpath refid="libraries.path" />
</javac>
</target>
<!-- Sonar -->
<target name="sonar" depends="junit">
<taskdef uri="antlib:org.sonar.ant" resource="org/sonar/ant/antlib.xml">
<!-- Update the following line, or put the "sonar-ant-task-*.jar" file in your "$HOME/.ant/lib" folder -->
<classpath path="D:/sonarqube-4.1/lib/sonar-ant-task-2.1.jar" />
</taskdef>
<!-- Execute the SonarQube analysis -->
<sonar:sonar />
</target>
<!-- Junit with Coverage -->
<target name="junit" depends="build">
<taskdef uri="antlib:org.jacoco.ant" resource="org/jacoco/ant/antlib.xml">
<classpath path="lib/jacocoant.jar" />
</taskdef>
<jacoco:coverage destfile="${reports.jacoco.dir}/jacoco.exec">
<junit fork="true" forkmode="once">
<classpath refid="libraries.path" />
<formatter type="plain" />
<batchtest fork="yes" todir="${report.junit}">
<fileset dir="tests">
<include name="**/*Test*.java" />
<exclude name="**/AllTests.java" />
</fileset>
</batchtest>
</junit>
</jacoco:coverage>
<!-- Create Local Reports as well -->
<jacoco:report>
<executiondata>
<file file="${reports.jacoco.dir}/jacoco.exec" />
</executiondata>
<structure name="Some Legacy Code">
<classfiles>
<fileset dir="bin" />
</classfiles>
<sourcefiles encoding="UTF-8">
<fileset dir="src" />
</sourcefiles>
</structure>
<html destdir="report/jacoco" />
</jacoco:report>
</target>
</project>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment