Skip to content

Instantly share code, notes, and snippets.

@nitsanw
Last active December 11, 2015 10:38
Show Gist options
  • Save nitsanw/4587721 to your computer and use it in GitHub Desktop.
Save nitsanw/4587721 to your computer and use it in GitHub Desktop.
Build your project using Ivy
<project xmlns:ivy="antlib:org.apache.ivy.ant" name="TheBestestProjectEver" default="build">
<property name="ivy.install.version" value="2.0.0-beta1" />
<property name="ivy.jar.dir" value="${basedir}/ivy" />
<property name="ivy.jar.file" value="${ivy.jar.dir}/ivy.jar" />
<property name="allocation.jar.file" value="${basedir}/lib/allocation.jar" />
<condition property="skip.download.ivy">
<and>
<available file="${ivy.jar.file}"/>
</and>
</condition>
<condition property="skip.download.allocation">
<and>
<available file="${allocation.jar.file}"/>
</and>
</condition>
<property name="build.dir" value="build" />
<property name="src.dir" value="src" />
<property name="experiments.dir" value="experiments" />
<target name="download-ivy" unless="skip.download.ivy">
<mkdir dir="${ivy.jar.dir}" />
<!--
download Ivy from web site so that it can be used even without any special installation
-->
<echo message="downloading ivy..." />
<get src="http://repo1.maven.org/maven2/org/apache/ivy/ivy/${ivy.install.version}/ivy-${ivy.install.version}.jar" dest="${ivy.jar.file}" usetimestamp="true" />
</target>
<target name="download-allocation-jar" unless="skip.download.allocation">
<mkdir dir="lib" />
<!--
download allocation jar, I'm sure there's a better way to do this with Ivy, but fuck it
-->
<echo message="downloading allocation jar.." />
<get src="http://java-allocation-instrumenter.googlecode.com/files/allocation.jar" dest="${allocation.jar.file}" usetimestamp="true" />
</target>
<!--
this target is not necessary if you put ivy.jar in your ant lib directory if you already have ivy in your ant lib, you can simply remove this target and the dependency the 'go' target has on it =================================
-->
<target name="install-ivy" depends="download-ivy" description="--> install ivy">
<!--
try to load ivy here from local ivy dir, in case the user has not already dropped it into ant's lib dir (note that the latter copy will always take precedence). We will not fail as long as local lib dir exists (it may be empty) and ivy is in at least one of ant's lib dir or the local lib dir.
-->
<path id="ivy.lib.path">
<fileset dir="${ivy.jar.dir}" includes="*.jar" />
</path>
<taskdef resource="org/apache/ivy/ant/antlib.xml" uri="antlib:org.apache.ivy.ant" classpathref="ivy.lib.path" />
</target>
<!-- Build using the classpath defined by the ivy.xml file found in the same directory -->
<target name="build" depends="install-ivy" description=" resolve dependencies, and compile project">
<ivy:cachepath pathid="lib.path.id" />
<echo message="compiling..." />
<mkdir dir="${build.dir}" />
<javac srcdir="${src.dir}" destdir="${build.dir}" classpathref="lib.path.id" />
<javac srcdir="${experiments.dir}" destdir="${build.dir}" classpathref="lib.path.id" />
</target>
</project>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment