Setting up an Ant build script for your Scala project

Introduction

This is a small writeup which gives one way of setting up a build system for your Scala project. Here Apache Ant is used for managing this process, where the whole configuration is contained within a single build.xml file placed in the project’s root directory. Execution is done from command line or within your IDE environment.

Prerequisites

Install and configure Scala:

  • Define and set the SCALA_HOME variable in the OS environment
  • Update the PATH variable in the OS environment to include SCALA_HOME\bin directory

Install and configure Ant:

  • Define and set the ANT_HOME variable in the OS environment
  • Update the PATH variable in the OS environment to include ANT_HOME\bin directory
  • Optional: If you encounter memory problems, define and set ANT_OPTS=-Xmx500M with JVM memory configuration in the OS environment

Install and configure Java:

  • Define and set the JAVA_HOME variable in the OS environment
  • Update the PATH variable in the OS environment to include JAVA_HOME\bin directory

Find a suitable file structure for the project:

project-name/
  build/
  lib/
  src/
  test/
  build.xml

The Ant build script

Order of Ant targets:

  • build <- package <- doc <- compile <- init
  • clean <- init

Configure project-name/build.xml:


 

  Project Build Script
 
  
  
 
  
    
  
 
  
    
 
    
    
      
    
    
      
    
 
    
    
    
    
    
    
    
    
    
    
    
    
 
    
      
       
    
 
    
      
      
      
    	
 
    
    
 
    
    
    
    
 
    
    
      
      
    
  
 
  
    
    
      
      
    
  
 
  
    
    
      
    
  
 
  
    
    
      
    
    
      
    
    
      
    
     
  

References

2 thoughts on “Setting up an Ant build script for your Scala project

  1. Strange, my system’s installation of Scala doesn’t have a “scala/tools/ant/antlib.xml” anywhere. Where are we supposed to find that?

  2. The “scala/tools/ant/antlib.xml” is located within the scala-compiler.jar, which itself is located at %SCALA_HOME%/lib/. Might be related to a problem with the script. I updated the check in init to reference env.SCALA_HOME and env.JAVA_HOME properly, and verified it that it ran when everything is configured correctly.

Leave a Reply

Your email address will not be published. Required fields are marked *