Scala Project with Ant, Ivy and ScalaTest

Building a library project using Ant, Ivy, ScalaTest and Scaladoc?
Jumpstart by using this skeleton project.

I was working on a Scala project which needed to be packaged as a library (jar) for used by other Scala/Java projects. My goal was to keep the build file pretty simple without requiring any external dependencies (like having to install scala). I wanted to use:

You can also download the entire skeleton project here and execute ant to build, test and publish the skeleton project jar to local repo.

Lets look at ivy.xml first:

We have three configurations to keep the downloaded dependencies separate. This is usually a good idea, so as to not muddle up your test dependencies with the ones needed only at runtime or at compile time. So, we have:

  1. core: This is the main library dependencies. If your library needs Commons DBCP, you'd put it in this configuration. If my example, I've listed gson and slf4j as the core dependencies.
  2. test: This extends core and adds ScalaTest lib on top of the ones in core.
  3. scala-lang: This fetches scala compiler and library jars.

Now, build.xml:

Here the main targets are:

  • docs: builds scaladocs
  • build: builds jar
  • test: runs tests
  • publish: publishes the jar into local repo