Tuesday, December 22, 2009

A Basic Ant+Ivy+Scala Setup

I've decided that for my latest project I'd give Ant with Ivy a go as my build system. To start with, I'm going to try for the simplest possible setup necessary in order to compile my project (so at this stage, it's not even rolling the output up into a jar - I can fix that later). At it's most basic level, this means that I'll need two XML files to get everything to build:

ivy.xml

ivy.xml contains information about the dependencies needed to build the project. To compile scala source, I'll need to add two dependencies - scala-library and scala-compiler.

<ivy-module version="2.0">
<info organisation="com.maethorechannen" module="snow-core"/>
<dependencies>
<dependency org="org.scala-lang" name="scala-library" rev="2.7.7"/>
<dependency org="org.scala-lang" name="scala-compiler" rev="2.7.7"/>
<!-- other dependecies -->
</dependencies>
</ivy-module>


If you've used Maven then this will look vaguely familiar yet more compact - groupId becomes org, artifactId becomes name and version becomes rev. As by default Ivy uses Maven's repositories, you can use the same values as you would in Maven.

build.xml

My build.xml will need to do 3 things:

  1. download ivy

  2. setup scala

  3. compile



Strictly speaking, the first item is not technically required if I manually install Ivy into Ant. For the moment, it seems easier if I just set it up so that Ivy gets automagically installed if need be. Fortunatly, the ivy-go example build.xml file shows us how to do this.

The Scala side of things is also fairly straightforward. The scala-lang.org page on Scala Ant Tasks gave me a fairly good idea of what needed to be done, however I had to make a few changes:

  • make the init target depend on the install-ivy target

  • modify init so that it executes ivy:retrieve (which downloads the dependencies) and modify the way init generates the build classpath so that it includes jars from the lib directory

  • modify the taskdef that imports the scala tasks (also in the init target) so that it finds scala-compiler and scala-library in the lib directory and not in scala.home

  • modify the build target, so that it compiles all scala source files in the src/main/scala directory and subdirectories



As the build.xml file is a bit big for a blog post, you can find it here

2 comments:

Channing Walton said...

You might want to give sbt a try too, its very compact and is built on top of maven/ivy: http://code.google.com/p/simple-build-tool/

kimberly said...

When I bought my computer and I didn´t know how to use java graphics, so I decided looking for information in a webside and I found an useful information that helped me a lot.. Now I am interested in to do the best investment and I found a webside very useful and interesting called costa rica investment opportunities , I think it´s a very wonderful site.