Friday, 23 October 2015

Using FindBugs, CheckStyle and PMD from IntelliJ with QAplug to improve your Java Coding

  • A short video showing PMD, Checkstyle and Findbugs running from IntelliJ
  • Why you would want to use them
  • And hints and tips on getting the plugins working on Mac
I’m always looking for simple ways that I can improve my Java programming.

Recently I’ve been working with PMD and Findbugs in my IDE.

I stumbled across the QAPlug, IntelliJ plugin which makes it easy to bundle in the FindBugs, CheckStyle and PMD plugins.

These each check for different issues and suggestions but basically statically analyse either the source or compiled byte code to provide a list of suggestions.

QAPlug wraps it all up in an right click menu item to Analyze the source code and shows all the items in a handy list for you to work through.

Just make sure you double click on the lowest branch in the tree to jump right to the code position where the tool identified the issue or suggestion.

This is like having a coach sitting by you when you are writing code. And some of the suggestions the tools make you won’t understand, so you have to search and learn what they mean - forcing you to learn that little bit more about your chosen language.

And don’t take all the suggestions at face value. You choose which suggestions to act on, and you can configure the tools to warn you about some things and not others.

Over time, you might choose to add the command line and build versions of the tools into your CI process rather than just your personal coding approach.

Mac Install

Note that on my Mac I had to take some additional steps to get them working since my Mac wasn’t using Java 1.8 to run IntelliJ.

When I restarted my ide - disaster. The project wouldn’t load because the plugin couldn’t start

“cannot load project com.intellij.ide.plugins.pluginmanager$startupabortedexception…"

So I searched and this was the most relevant result for me

https://youtrack.jetbrains.com/issue/IDEA-126847

With the suggested solution being:
  • Copy bin/idea/properties to ~/Library/Preferences/IntelliJIdea14/idea.properties file.
  • cp /Applications/IntelliJ\ IDEA\ 14.app/Contents/bin/idea.properties ~/Library/Preferences/IntelliJIdea14/idea.properties
  • Change JVMVersion=1.6* to JVMVersion=1.6+ (I have JDKs 1.6, 1.7 and 1.8 installed on my machine).
  • restart IntelliJ IDEA
This seems to run it on java 1.8 - assuming you have set 1.8 to be the default jdk