Configure Code Analysis Tools with Gradle
I’m really happy that configuring Checkstyle, Findbugs and PMD with Gradle is so easy. So if you want to see how I configured the tools than have a quick look at this code snippet gist: https://gist.github.com/claudioaltamura/a9e59c009db38d615dae
After you have configured your Code Analysis Tool, you just have to type in:
gradle check
How do I configure Checkstyle, Findbugs or PMD?
Checkstyle
This is a checkstyle.xml file with one check.
[code language=“xml“]
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE module PUBLIC
"-//Puppy Crawl//DTD Check Configuration 1.3//EN"
"http://www.puppycrawl.com/dtds/configuration_1_3.dtd">
<module name="Checker">
<module name="TreeWalker">
<module name="UnusedImports"/>
</module>
</module>
[/code]
So if you like to add available checks, go to this site http://checkstyle.sourceforge.net/checks.html and http://checkstyle.sourceforge.net/config.html for general configuration.
Findbugs
If you remove the property ‚includeFilter‘, you do a full findbugs check. If you are interested only into a few filter then check these two sites http://findbugs.sourceforge.net/bugDescriptions.html and
http://findbugs.sourceforge.net/manual/filter.html.
Just include findbugs.xml file and your filters like this:
[code language=“xml“]
<?xml version="1.0" encoding="UTF-8"?>
<FindBugsFilter>
<Match>
<Bug code="ODR" />
</Match>
</FindBugsFilter>
[/code]
PMD
Here you can see a typcial PMD ruleset.xml file.
[code language=“xml“]
<?xml version="1.0"?>
<ruleset name="Custom ruleset"
xmlns="http://pmd.sourceforge.net/ruleset/2.0.0"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://pmd.sourceforge.net/ruleset/2.0.0 http://pmd.sourceforge.net/ruleset_2_0_0.xsd">
<description>
This ruleset checks my code for bad stuff
</description>
<rule ref="rulesets/java/basic.xml" />
<rule ref="rulesets/java/design.xml" />
</ruleset>
[/code]
For configuration see https://pmd.github.io/pmd-5.3.3/pmd-java/rules/index.html
or https://pmd.github.io/pmd-5.3.3/usage/running.html
Have Fun!
Picture License: CC0 Public Domain / geralt