Thanks to Tim Vernum for responding to my last post about Detecting Cycles with ANT/JDepend, I now know about the tool Classycle which is much better suited for the task. Here is the ANT target I added to my build.xml file replacing the old approach:

  <target name="classycle" depends="-init">
    <taskdef name="classycleDependencyCheck"
             classname="classycle.ant.DependencyCheckingTask"
             classpath="${project.root}/build-stuff/tools/classycle-1.3.3/classycle.jar"
             />
    <classycleDependencyCheck failOnUnwantedDependencies="true">

      <fileset dir="${mother.target}/dist">
        <include name="shared-${build.revision}.jar"/>
        <include name="datareceipt-DO-NOT-USE-${build.revision}.jar"/>
        <include name="webapp-DO-NOT-USE-${build.revision}.jar"/>
      </fileset>

      show allPaths onlyFailures
      {root} = au.gov.defence.mldef
      [all] = ${root}.*
      check absenceOfPackageCycles > 1 in [all]
    </classycleDependencyCheck>

  </target>

As you can see this is a lot smaller and simpler than the previous approach.

Some notes:

  • Another nice advantage of this approach is that you do not need to classcyle.jar to your ${ANT\_HOME}/lib directory. With the JDepend approach you need to add the JDepend JAR file to the ${ANT\_HOME}/lib directory.
  • I still use the Checkstyle ImportControl check for enforcing the project layering/dependency rules. The immediate feedback this gives in the Eclipse IDE via the eclipse-cs is invaluable. That said, Classycle looks very capable.