Hi there fellow reader,
today I’m gonna show how you can configure your Jenkins job to use your custom Checkstyle rules.
I assume you already know the development tool Checkstyle to improve your code quality.
If not, you should check it out! Follow me to the Checkstyle homepage 🙂
References for Checkstyle
The Checkstyle routine is based on an XML document which contains information about the rules that should be checked and applied.
You can find the original (Vanilla) Sun Coding checks here: https://github.com/checkstyle/checkstyle/blob/master/src/main/resources/sun_checks.xml
If you want to read more about the available checks, check out this page
You now need to add the checkstyle goal to your build configuration
The -Dcheckstyle.config.location=”” is the location of your Checkstyle rules
My checkstyle example can be found here
At first I tried to access my XML file via the SSL option of CloudFlare but encountered the following error
sun.security.provider.certpath.SunCertPathBuilderException: unable to find valid certification path to requested target
It seems that Maven could not validate the SSL cert – sadly a known issue of CloudFlare’s SSL and self signed certificates.
Edit: 2017/01/06: Recent Java and Maven (at least 3.2.5) versions are capable of CloudFlare and Let’s Encrypt certificates!
However, Browser Integrity Check is recommended to be turned off.
I decided to host the file without SSL but ran into the Browser Integrity Check of CloudFlare.
This can be bypassed with a Page rule
Make sure that
- SSL – off
- Browser Integrity Check – off
- Custom caching – Bypass cache
- Apps – off
- Performance – off
If you receive an error like
cannot initialize module TreeWalker - Unable to instantiate RedundantThrows: Unable to instantiate RedundantThrowsCheck
you will need to modify your checkstyle.xml.
With version 6.2 of Checkstyle some checks were removed without any replacement.
Affected checks are StrictDuplicate and RedundantThrows
Please refer to the release notes, too.
Thanks for reading and feel free to comment if you need help.