If you believe in the proverb – a picture is worth thousand words, then you would love this one. A few bloggers recently posted how Grand and Graphviz can be used for generating graphical views of the ANT dependencies. After a bit of research into how Grand achieved the task, I was inspired to do a similar thing, albeit on a different set of XML files (not on ANT scripts).In this post I will go over how these tools work together, and in the next part I will go over the details of creating a DOT file and generating the graphs to your liking.Before getting into the details, a quick summary of these tools below:
Grand
“Grand is a tool to create visual representation of ant target dependencies. It differs from tools like VizantAntGraph by a totally different approach, relying on the Ant API rather than parsing directly the XML files. This enables Grand to provide some nifty features such as the support of the ant 1.6.x tasks like import or subant“.
Grand has a GUI, I haven’t used it as I wanted to invoke this from ANT (or from command line).
Graphviz
“Graphviz is open source graph visualization software. It has several main graph layout programs. See the gallery for some sample layouts. It also has web and interactive graphical interfaces, and auxiliary tools, libraries, and language bindings.”
“The Graphviz layout programs take descriptions of graphs in a simple text language, and make diagrams in several useful formats such as images and SVG for web pages, Postscript for inclusion in PDF or other documents; or display in an interactive graph browser. (Graphviz also supports GXL, an XML dialect.)”
Graph of ANT dependencies
For the demonstration purpose I’m using Spring Framework’s build.xml.
Some obvious steps:
- Download Grand JAR
- Download and install Graphviz
Not so obvious ones:
- Create a typedef in your ANT build file
<typedef resource="net/ggtools/grand/antlib.xml" classpath="lib/grand-1.8.jar" /> - Write an ANT target
<target name="SpringFramework-BuildDiagram"> <grand output="docs/spring-framework.dot" buildfile="spring-framework-build.xml"> <exec executable="dot" dir="docs"> <arg line="-Tpdf -Gsize=11.69,8.27 -Grotate=90 -o spring-framework.pdf spring-framework.dot"/> </exec></target>
This is a two step process as described in the above target:
- First step is to generate the dot file (note: this has got no relation with MS Word’s dot template). DOT is a plain text description language of graphs. Provide an output path and what build file you need a diagram for.
- Using that dot file graphviz generates the output graphs. Graphviz supports a wide range of output options. The above targets invoke dot and provides output type as PDF, provides the paper size to print on, and -Grotate value indicates the output to be rotated 90 degrees for landscape mode.
Here is a jpg output for Spring framework’s build file –

Grand supports filters to remove any targets from the graph that you are not interested in. For example, if you are not interested in test-related targets and in isolated nodes (nodes that have no connections) the following ANT target achieves that functionality –
<target name="SpringFramework-BuildDiagram"> <grand output="docs/spring-framework.dot" buildfile="spring-framework-build.xml"> <filter name="removenode" node="clover.tests"/> <filter name="removenode" node="clean.compile"/> <filter name="isolatednode"/> </grand>
<exec executable="dot" dir="docs"> <arg line="-Tpdf -Gsize=11.69,8.27 -Grotate=90 -o spring-framework.pdf spring-framework.dot" /> </exec></target>
Resulting Graph –


Follow on Twitter