Definitions

Dependency Finder defines a number of tasks for use with the Ant build tool from the Apache Foundation. You need to tell Ant where to find the classes that implement these tasks and their support classes. The tasks need the following elements on the CLASSPATH from the Dependency Finder distribution:

It is better if you put classes first. This way, patch files that come as loose classes will take precedence over the older definitions in DependencyFinder.jar.

In your buildfile

One easy to do this is to define a global <path> tag as part of the Ant project.

    <!-- Replace "value" with your installation's directory -->
    <property name="dependencyfinder.home" value="C:/DependencyFinder"/>

    <path id="dependencyfinder">
        <pathelement location="${dependencyfinder.home}/classes"/>
        <pathelement location="${dependencyfinder.home}/lib/DependencyFinder.jar"/>
        <pathelement location="${dependencyfinder.home}/lib/jakarta-oro.jar"/>
        <pathelement location="${dependencyfinder.home}/lib/log4j.jar"/>
    </path>

Some people might want to add these JAR files directly to their Ant installation. This way, they do not have to deal with the CLASSPATH and extra property. I don't recommend you do this because it makes upgrading Ant that much more difficult. Every time, you must remember to copy the files again. Also, you cannot deal with the classes directory in the same fashion and this could mean missing out on Dependency Finder patches.

Whatever you do, make sure that Ant can find log4j.properties to initialize Log4J properly. If you don't, the default Log4J configuration will log everything to a dummy appender and the tasks will take much longer to execute.

Once Ant knows where to find the Dependency Finder classes, you can use the path-like structures to import the predefined tasks supplied by Dependency Finder.

    <taskdef resource="dependencyfindertasks.properties">
        <classpath refid="dependencyfinder"/>
    </taskdef>

The resource file DependencyFinderTasks.properties is already part of DependencyFinder.jar. It looks like the following:

    classmetrics=com.jeantessier.dependencyfinder.ant.ClassMetrics
    dependencyextractor=com.jeantessier.dependencyfinder.ant.DependencyExtractor
    dependencyreporter=com.jeantessier.dependencyfinder.ant.DependencyReporter
    dependencyclosure=com.jeantessier.dependencyfinder.ant.DependencyClosure
    dependencymetrics=com.jeantessier.dependencyfinder.ant.DependencyMetrics
    listdeprecatedelements=com.jeantessier.dependencyfinder.ant.ListDeprecatedElements
    oometrics=com.jeantessier.dependencyfinder.ant.OOMetrics
    jarjardiff=com.jeantessier.dependencyfinder.ant.JarJarDiff
    listdiff=com.jeantessier.dependencyfinder.ant.ListDiff

Renaming the tasks

If you don't like the tasks' predefined names, you can define your own with Ant's <taskdef> task.

    <taskdef name="metrics.class" classname="com.jeantessier.dependencyfinder.ant.ClassMetrics">
        <classpath refid="dependencyfinder"/>
    </taskdef>
    
    <taskdef name="extractor" classname="com.jeantessier.dependencyfinder.ant.DependencyExtractor">
        <classpath refid="dependencyfinder"/>
    </taskdef>
    
    <taskdef name="reporter" classname="com.jeantessier.dependencyfinder.ant.DependencyReporter">
        <classpath refid="dependencyfinder"/>
    </taskdef>
    
    <taskdef name="closure" classname="com.jeantessier.dependencyfinder.ant.DependencyClosure">
        <classpath refid="dependencyfinder"/>
    </taskdef>
    
    <taskdef name="metrics.dependency" classname="com.jeantessier.dependencyfinder.ant.DependencyMetrics">
        <classpath refid="dependencyfinder"/>
    </taskdef>
    
    <taskdef name="list.deprecated.elements" classname="com.jeantessier.dependencyfinder.ant.ListDeprecatedElements">
        <classpath refid="dependencyfinder"/>
    </taskdef>
    
    <taskdef name="metrics.oo" classname="com.jeantessier.dependencyfinder.ant.OOMetrics">
        <classpath refid="dependencyfinder"/>
    </taskdef>
    
    <taskdef name="diff" classname="com.jeantessier.dependencyfinder.ant.JarJarDiff">
        <classpath refid="dependencyfinder"/>
    </taskdef>
    
    <taskdef name="list.diff" classname="com.jeantessier.dependencyfinder.ant.ListDiff">
        <classpath refid="dependencyfinder"/>
    </taskdef>

Or use your own properties file. For example, given the following mytasks.properties file:

    metrics.class=com.jeantessier.dependencyfinder.ant.ClassMetrics
    extractor=com.jeantessier.dependencyfinder.ant.DependencyExtractor
    reporter=com.jeantessier.dependencyfinder.ant.DependencyReporter
    closure=com.jeantessier.dependencyfinder.ant.DependencyClosure
    metrics.dependency=com.jeantessier.dependencyfinder.ant.DependencyMetrics
    list.deprecated.elements=com.jeantessier.dependencyfinder.ant.ListDeprecatedElements
    metrics.oo=com.jeantessier.dependencyfinder.ant.OOMetrics
    diff=com.jeantessier.dependencyfinder.ant.JarJarDiff
    list.diff=com.jeantessier.dependencyfinder.ant.ListDiff

Which you can use in your buildfile:

    <taskdef file="mytasks.properties"/>

Copyright © 2001-2009 Jean Tessier. All rights reserved.