JDepend design metrics in CI
Join the DZone community and get the full member experience.
Join For Free
this article is intended to give the reader enough information to
understand what jdepend is, what it does, and how to use it in a maven
build. it’s a kind of cheat sheet, if you like.
what is it?
jdepend is more of a design metric than a code metric, it gives you
information about your classes with regards to how they’re related to
each other. using this information you should be able to identify any
unwanted or dubious dependencies.
how does it do that?
it traverses java class files and generates design quality metrics, such as:
- number of classes and interfaces
- afferent couplings (ca) – what is this?? someone probably feels very proud of themselves for coming up with this phrase. afferent coupling means the number of other packages which depend on the package being measured, in a nutshell. jdepend define this as a measure of a package’s “responsibility”
- efferent couplings (ce) – sort of the opposite of ca. it’s a measure of the number of other packages that your package depends on
- abstractness (a) – the ratio of abstract classes to total classes.
- instability (i) – the ratio of efferent coupling (ce) to total coupling (ce + ca)
- distance from the main sequence (d) – this sounds fairly wishy-washy and i’ve never paid any attention to it. it’s defined as: “an indicator of the package’s balance between abstractness and stability”. meh.
to use jdepend with maven you’ll need maven 2.0 or higher and jdk 1.4 or higher. you don’t need to install anything, as maven will sort this out for you by downloading it at build time.
here’s a snippet from one of my project poms, it comes from in the <reporting> section:
<plugin> <groupid>org.codehaus.mojo</groupid> <artifactid>jdepend-maven-plugin</artifactid> <configuration> <targetjdk>1.6</targetjdk> <outputdirectory>build/maven/${pom.artifactid}/target/jdepend-reports</outputdirectory> </configuration> </plugin>
what you’ll get is a jdepend entry under the project reports section of your maven site, like this:
and this is what the actual report looks like (well, some of it):
summary:
jdepend isn’t something i personally use very heavily, but i can understand how it could be used to good effect as a general measure of how closely related your classes are, which, in certain circumstances could prompt you to redesign or refactor your code.
i don’t think this sort of information is required on a per commit basis, so i’d be tempted to only include it in my nightly reports. however, i also use sonar, and that has a built-in measure of afferent coupling, so if you’re only interested in that measurement and you’re already running sonar, then jdepend is probably a bit of an unnecessary overhead. also, sonar itself has some good plugins which can provide architectural and design governance features, at least one of which i know implemented jdepend.
source: http://jamesbetteley.wordpress.com/2011/04/06/jdepend-design-metrics-in-ci/
Opinions expressed by DZone contributors are their own.
Comments