Code Quality Tools in Java
Join the DZone community and get the full member experience.
Join For Freethere are several tools to measure the code quality. the ones i have tried with a lot of success are:
-
findbugs
(latest version 1.3.8) –
uses static analysis to look for bugs in java code
.
this is a great tool, it discovered possible nullpointerexceptions and
a lot more bugs in my projects. sometimes i asked myself how this
program could have discovered this ‘complicated’ bug.
with the maven plugin
you can do:
mvn findbugs:findbugs
which will use version 1.3.8 out of the box
-
pmd
(latest version 4.2.5) –
scans java source code and looks for potential problems
.
the rules are configurable, but at the beginning you will only need the
provided one (and spend a lot of time to choose your favourites
)in netbeans 6.5 this tool is well integrated and works like a charme (ctrl+alt+p).
with the maven plugin you can do:
mvn pmd:pmd
after you specified the following in the pom.xml under<reporting> <plugins> :
<plugin>
<groupid>org.apache.maven.plugins</groupid>
<artifactid>maven-pmd-plugin</artifactid>
<version>2.3</version>
<configuration>
<targetjdk>1.5</targetjdk>
</configuration>
</plugin>
other tools could be
- jaranalyzer – is a dependency management utility for jar files. it’s primary purpose is to traverse through a directory, parse each of the jar files in that directory, and identify the dependencies between the jar files.
- hammurapi – a code quality governance platform
but i haven’t tried them so far.
for findbugs and pmd there is a netbeans plugin ( sqe … software quality environment ) which looks promising, but fails with a nullpointerexception after i installed it via the update center and tried it on my project. maybe i should use one of the snapshots . (btw: i successfully used the pmd-plugin and findbugs in the standalone version).
sonar is another interesting approach to use several code quality tools at a time. with sonar it is possible to see the violations or possible bugs over das or weeks – so, you are looking at the improvements and you will not get lost in the mass of bugs at the beginning. another “multi-tooling” project is xradar .
a little bit offtopic, but a great tool is proguard, which shrinks, optimizes, obfuscates and preverifies java class files. there is even a maven plugin for that.
Opinions expressed by DZone contributors are their own.
Trending
-
Reactive Programming
-
Strategies for Reducing Total Cost of Ownership (TCO) For Integration Solutions
-
Alpha Testing Tutorial: A Comprehensive Guide With Best Practices
-
Front-End: Cache Strategies You Should Know
Comments