Automatic Dojo Builds

By on October 28, 2008 1:30 am

The build system that is part of the Dojo Toolkit is an incredibly powerful tool. Making sure that your custom build is always up-to-date in your web application can be time consuming and error prone if done manually. This post will demonstrate how to quickly add custom Dojo builds into any web application that uses Apache Ant.

I’ll assume that you have Dojo setup in you project and you are already using or are familiar with the Dojo build system. If you want to learn more about the Dojo build system, the official documentation provides a good overview.

While Ant is not a requirement for building Dojo, Ant is a very popular build tool and integration with Ant is key for many web applications. To get things started, Ant’s exec task can be used to kick off the existing provided by Dojo:


Add the command line arguments you would normally pass to as arg elements. Because the exec task simply wraps the command line, you will need to pass absolute paths anywhere there is a path. The standard ${basedir} ant property will keep the execution inside your project without the need to hardcode the full filesystem path.

The Dojo Toolbox provides an excellent desktop graphical user interface for building Dojo, and also for generating the command line arguments that can be used to customize the Dojo build process.

If your Ant build copies the contents of your web application from the source tree to a temporary build directory, then you will want to exclude the source tree Dojo Toolkit directories from that copy and execute the above build from the source tree. The Dojo build will copy all needed files that are part of the build. It will not copy test files unless you explicitly include them. Doing this step will significantly reduce the size of your war file.

If your projects directory structure looks something like this:


Then adding an exclude to the fileset of the copy will speed up your build times and reduce the size of your war file:


Note: make sure your run the copy command before the exec command.

So far the examples shown here will build Dojo every time you build your web application, even if the Dojo source code has not changed. The script does not check for file changes unlike Ant. If you are making changes to the Java code in your app and not touching your JavaScript code, then you will be spending most of your time waiting for Dojo to rebuild itself without any additional benefit.

The Ant-Contrib project provides a solution to this problem in the form of the outofdate task. This task allows ant to compare two file sets and only execute commands if the files are found to be out of date. If you aren’t already using Ant-Contrib in your Ant build, their website includes instructions on how to start using it.

Replace the exec command from above with this block of code:


Now incremental builds will not rebuild the Dojo directory unless the Dojo directory in your source tree has changed. The example above also checks your custom Dojo profile so that any changes to it will also kick off a build. If you have any other directories outside of Dojo which are part of the Dojo build, then be sure to include them in the fileset of the sourcefiles.

Using these techniques will ensure that your war file or web application always has the latest built copy of Dojo and reduces the time it take to execute incremental builds. If you have integrated the Dojo build system into your project using a different technique or are using a different build tool such as maven, please leave a comment and let us know about your experiences.